Fix problem in import bank (fgetcsv has changed) and add ajax abilities
This commit is contained in:
parent
9714914c1c
commit
fa0eb3fbdb
14 changed files with 213 additions and 51 deletions
75
html/ajax_import.php
Normal file
75
html/ajax_import.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?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
|
||||
*/
|
||||
/* $Revision$ */
|
||||
|
||||
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
|
||||
|
||||
/* !\file ajax file called by the import screen
|
||||
*/
|
||||
|
||||
/* \brief update , delete or remove a record from the confirmed list
|
||||
*
|
||||
*/
|
||||
include_once ("constant.php");
|
||||
include_once ("postgres.php");
|
||||
include ('class_user.php');
|
||||
require_once ('class_dossier.php');
|
||||
|
||||
|
||||
|
||||
$cn=DbConnect(dossier::id());
|
||||
|
||||
$User=new cl_user($cn);
|
||||
$User->Check();
|
||||
if ( isset ($_GET['action']) &&
|
||||
$_GET['action']=='update'
|
||||
)
|
||||
|
||||
{
|
||||
$code=FormatString($_GET['code']);
|
||||
$count=FormatString($_GET['count']);
|
||||
$poste=FormatString($_GET['poste']);
|
||||
$concern=FormatString($_GET['concerned']);
|
||||
$sql = "update import_tmp set poste_comptable='$poste' ,status='w',".
|
||||
"jr_rapt='$concern' where code='$code'";
|
||||
|
||||
$Res=ExecSql($cn,$sql);
|
||||
exit();
|
||||
}
|
||||
|
||||
if ( isset ($_GET['action']) &&
|
||||
$_GET['action']=='delete'
|
||||
)
|
||||
|
||||
{
|
||||
$code=FormatString($_GET['code']);
|
||||
$sql="update import_tmp set status='d' where code='".$code."'";
|
||||
ExecSql($cn,$sql);
|
||||
exit();
|
||||
}
|
||||
if ( isset ($_GET['action']) &&
|
||||
$_GET['action']=='not_confirmed'
|
||||
)
|
||||
|
||||
{
|
||||
$code=FormatString($_GET['code']);
|
||||
$sql="update import_tmp set status='n' where code='".$code."'";
|
||||
ExecSql($cn,$sql);
|
||||
exit();
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@ $User=new cl_user($cn);
|
|||
$User->Check();
|
||||
|
||||
html_page_start($User->theme);
|
||||
|
||||
echo JS_PROTOTYPE_JS;
|
||||
|
||||
/* Admin. Dossier */
|
||||
|
||||
|
|
@ -80,22 +80,12 @@ if ( isset ($_GET["action"]) ) {
|
|||
echo "</DIV>";
|
||||
}
|
||||
}
|
||||
if ( isset ($_POST['trashit'])) {
|
||||
DropRecord($cn,$_POST['code']);
|
||||
echo '<DIV class="u_redcontent">';
|
||||
VerifImport($cn);
|
||||
echo "</DIV>";
|
||||
exit();
|
||||
}
|
||||
if ($action == "verif" ) {
|
||||
if(isset($_POST['count'])) {
|
||||
UpdateCSV($cn);
|
||||
}
|
||||
|
||||
echo '<DIV class="u_redcontent">';
|
||||
VerifImport($cn);
|
||||
echo "</DIV>";
|
||||
}
|
||||
|
||||
if ($action == "transfer" ) {
|
||||
|
||||
echo '<DIV class="u_redcontent">';
|
||||
|
|
|
|||
|
|
@ -233,3 +233,85 @@ function ca_set_parent(p_ctl,p_value) {
|
|||
f.value=p_value;
|
||||
|
||||
}
|
||||
/*! \brief import : update a record (in ajax)
|
||||
* \param $p_sessid : PHPSESSID
|
||||
* \param $p_dossier : the dossier id
|
||||
* \param $p_count : the item number
|
||||
*/
|
||||
|
||||
function import_update(p_sessid,p_dossier,p_count) {
|
||||
// alert ("Dossier = "+p_dossier+" counter ="+p_count);
|
||||
var query_string="PHPSESSID="+p_sessid+"&count="+p_count+"&gDossier="+p_dossier;
|
||||
var code=$("code"+p_count);
|
||||
var poste=$("poste"+p_count);
|
||||
var concerned=$("e_concerned"+p_count);
|
||||
var url="ajax_import.php";
|
||||
query_string+="&code="+code.value;
|
||||
query_string+="&poste="+poste.value;
|
||||
query_string+="&concerned="+concerned.value;
|
||||
query_string+="&action=update";
|
||||
|
||||
|
||||
/* call the script which handle the query */
|
||||
var update= new Ajax.Request (
|
||||
url,
|
||||
{
|
||||
method:'get',
|
||||
parameters:query_string,
|
||||
}
|
||||
);
|
||||
var form=$("form_"+p_count);
|
||||
form.hide();
|
||||
}
|
||||
/*! \brief remove : remove a record (in ajax)
|
||||
* \param $p_sessid : PHPSESSID
|
||||
* \param $p_dossier : the dossier id
|
||||
* \param $p_count : the item number
|
||||
*/
|
||||
|
||||
function import_remove(p_sessid,p_dossier,p_count) {
|
||||
// alert ("Dossier = "+p_dossier+" counter ="+p_count);
|
||||
var query_string="PHPSESSID="+p_sessid+"&count="+p_count+"&gDossier="+p_dossier;
|
||||
var code=$("code"+p_count);
|
||||
var url="ajax_import.php";
|
||||
query_string+="&code="+code.value;
|
||||
query_string+="&action=delete";
|
||||
var a = confirm("Etes-vous certain d'effacer cette operation ?");
|
||||
if ( a == false ) { return;}
|
||||
|
||||
/* call the script which handle the query */
|
||||
var update= new Ajax.Request (
|
||||
url,
|
||||
{
|
||||
method:'get',
|
||||
parameters:query_string,
|
||||
}
|
||||
);
|
||||
var form=$("form_"+p_count);
|
||||
form.hide();
|
||||
}
|
||||
/*! \brief remove : remove a record (in ajax)
|
||||
* \param $p_sessid : PHPSESSID
|
||||
* \param $p_dossier : the dossier id
|
||||
* \param $p_count : the item number
|
||||
*/
|
||||
|
||||
function import_not_confirmed(p_sessid,p_dossier,p_count) {
|
||||
// alert ("Dossier = "+p_dossier+" counter ="+p_count);
|
||||
var query_string="PHPSESSID="+p_sessid+"&count="+p_count+"&gDossier="+p_dossier;
|
||||
var code=$("code"+p_count);
|
||||
var url="ajax_import.php";
|
||||
query_string+="&code="+code.value;
|
||||
query_string+="&action=not_confirmed";
|
||||
|
||||
/* call the script which handle the query */
|
||||
var update= new Ajax.Request (
|
||||
url,
|
||||
{
|
||||
method:'get',
|
||||
parameters:query_string,
|
||||
}
|
||||
);
|
||||
var form=$("form_"+p_count);
|
||||
form.hide();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,28 +25,27 @@
|
|||
//-----------------------------------------------------
|
||||
// Bank Argenta
|
||||
//-----------------------------------------------------
|
||||
$line=1;
|
||||
$line=0;
|
||||
|
||||
while (($data = fgetcsv($handle, 2000,';')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,"!")) !== FALSE) {
|
||||
$num = count($data);
|
||||
|
||||
for ($c=0; $c < $num; $c++) {
|
||||
if ( $line==1) {
|
||||
$row=split(';',$data[$c]);
|
||||
$num_compte=$row[1];
|
||||
}
|
||||
|
||||
if ( $line == 2 )
|
||||
if ( $line < 2 )
|
||||
continue;
|
||||
//-----------------------------------------------------
|
||||
// Parsing CSV comes here
|
||||
//-----------------------------------------------------
|
||||
$row=split(';',$data[$c]);
|
||||
echo 'ici sizeof $row = '.sizeof($row);
|
||||
echo_debug('argenta',__LINE__,'$row = '.var_export($row,true));
|
||||
echo_debug('argenta',__LINE__,'sizeof($row)'.sizeof($row));
|
||||
if ( sizeof ($row) < 9 )
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
$date_exec=$row[5];
|
||||
$date_val=$row[5];
|
||||
|
|
@ -64,7 +63,9 @@ while (($data = fgetcsv($handle, 2000,';')) !== FALSE) {
|
|||
//----------------------------------------------------
|
||||
// Skip dubbel
|
||||
//----------------------------------------------------
|
||||
if ( CountSql($p_cn,"select * from import_tmp where code='$code' and num_compte='$num_compte' limit 2") != 0 )
|
||||
$code=FormatString($code);
|
||||
$num_compte=FormatString($num_compte);
|
||||
if ( CountSql($p_cn,"select * from import_tmp where code='$code' and num_compte='$num_compte' limit 2") != 0 )
|
||||
{
|
||||
/* Skip it it already encoded */
|
||||
echo "Doublon éliminé ".$detail;
|
||||
|
|
@ -107,15 +108,16 @@ echo "<br>";
|
|||
|
||||
catch(Exception $e)
|
||||
{
|
||||
echo_debug(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage);
|
||||
echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode." msg ".$e->getMessage);
|
||||
rollback($p_cn);
|
||||
break;
|
||||
}
|
||||
|
||||
} // for ($c=0;$c<$num;$c++)
|
||||
$line++;
|
||||
$line++;
|
||||
|
||||
} // file is read
|
||||
|
||||
fclose($handle);
|
||||
|
||||
commit($p_cn);
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
//-----------------------------------------------------
|
||||
$row=1;
|
||||
StartSql($p_cn);
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
|
||||
$num = count($data);
|
||||
echo_debug('cbc_be',__LINE__,$num);
|
||||
echo_debug('cbc_be',__LINE__,var_export($data,true));
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ class widget {
|
|||
$r=sprintf("$td
|
||||
<INPUT TYPE=\"button\" onClick=SearchJrn('%s',".dossier::id().",'%s',%s,'%s') value=\"Recherche\">
|
||||
%s $etd $td
|
||||
<INPUT TYPE=\"text\" style=\"color:black;background:lightyellow;border:solid 1px grey;\" NAME=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
|
||||
<INPUT TYPE=\"text\" style=\"color:black;background:lightyellow;border:solid 1px grey;\" NAME=\"%s\" ID=\"%s\" VALUE=\"%s\" SIZE=\"8\" readonly>
|
||||
$etd",
|
||||
$l_sessid,
|
||||
$this->name,
|
||||
|
|
@ -547,6 +547,7 @@ class widget {
|
|||
$this->extra2,
|
||||
$this->label,
|
||||
$this->name,
|
||||
$this->name,
|
||||
$this->value
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ define ("domaine","");
|
|||
define ("MAX_COMPTE",4);
|
||||
|
||||
|
||||
define ("DEBUG","false");
|
||||
define ("DEBUG","true");
|
||||
|
||||
// securite correspond a la table
|
||||
// action
|
||||
|
|
@ -225,7 +225,7 @@ function ChangeTVA(p_ctl,p_value) {
|
|||
define ("JS_AJAX_FICHE",'<script language="javascript" src="js/ajax_fiche.js"></script>');
|
||||
|
||||
define ("JS_AJAX_OP",'<script language="javascript" src="js/ajax_op.js"></script>');
|
||||
|
||||
define ("JS_PROTOTYPE_JS",'<script language="javascript" src="js/prototype.js"></script>');
|
||||
// Sql string
|
||||
define ("SQL_LIST_ALL_INVOICE","");
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ function echo_debug ($file,$line="",$msg="") {
|
|||
if ( DEBUG=='true' ) {
|
||||
$f=fopen ($_ENV['TMP'].DIRECTORY_SEPARATOR."phpcompta.log","a+");
|
||||
$a=var_export($msg,true);
|
||||
$e=basename($file);
|
||||
$e=basename($file);
|
||||
fwrite($f,"$e : $line $a\n");
|
||||
fclose ($f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ $LinesImported=0;
|
|||
$LinesDup=0;
|
||||
$row=1;
|
||||
StartSql($p_cn);
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE)
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
|
||||
{
|
||||
$num = count($data);
|
||||
echo_debug('dexia_be',__LINE__,$num);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ $LinesImported=0;
|
|||
$LinesDup=0;
|
||||
$row=1;
|
||||
StartSql($p_cn);
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
|
||||
$num = count($data);
|
||||
echo_debug('dexia_be',__LINE__,$num);
|
||||
echo_debug('dexia_be',__LINE__,var_export($data,true));
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// Bank type = eub
|
||||
//-----------------------------------------------------
|
||||
$row=1;
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
|
||||
$num = count($data);
|
||||
for ($c=0; $c < $num; $c++) {
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// Fortis Bank
|
||||
//-----------------------------------------------------
|
||||
$row=1;
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
|
||||
$num = count($data);
|
||||
for ($c=0; $c < $num; $c++) {
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ function UpdateCSV($p_cn){
|
|||
* modify the Quick Code or remove record poss.value are form, remove
|
||||
*/
|
||||
function ShowBox($p_val,$counter,$p_cn,$p_form='form'){
|
||||
echo JS_AJAX_FICHE;
|
||||
|
||||
$w=new widget('js_search_only');
|
||||
$w->name='poste'.$counter;
|
||||
$w->extra='cred';
|
||||
|
|
@ -97,6 +97,7 @@ function ShowBox($p_val,$counter,$p_cn,$p_form='form'){
|
|||
|
||||
// widget concerned
|
||||
$wConcerned=new widget('js_concerned');
|
||||
$wConcerned->name="e_concerned"+$counter;
|
||||
$wConcerned->extra=abs($p_val['montant']);
|
||||
$wConcerned->extra2='paid';
|
||||
$wConcerned->label='op. concernée';
|
||||
|
|
@ -117,7 +118,7 @@ function ShowBox($p_val,$counter,$p_cn,$p_form='form'){
|
|||
$f->GetByQCode($p_val['poste_comptable']);
|
||||
$s->value=$f->strAttribut(ATTR_DEF_NAME);
|
||||
}
|
||||
echo '<input type="hidden" name="code" value="'.$p_val['code'].'">';
|
||||
echo '<input type="hidden" id="code'.$counter.'" value="'.$p_val['code'].'">';
|
||||
echo '<input type="hidden" name="count" value="'.$counter.'">';
|
||||
echo '<table border="1" width="500">';
|
||||
echo '<tr><td width="200">'.$p_val['code'].'</td><td width="200">'.$p_val['date_exec'].'</td><td width="100">'.$p_val['montant'].' EUR</td><tr/>';
|
||||
|
|
@ -129,25 +130,33 @@ function ShowBox($p_val,$counter,$p_cn,$p_form='form'){
|
|||
|
||||
echo "<td>n° compte : ".$p_val['num_compte']."</td>";
|
||||
if ( $p_form == 'form') {
|
||||
echo '<td><input type="submit" value="Modifier">';
|
||||
echo '<input type="submit" name="trashit" value="Effacer.."></td><tr/>';
|
||||
$str_update=sprintf("import_update('%s','%s','%s');",
|
||||
$_REQUEST['PHPSESSID'],
|
||||
dossier::id(),
|
||||
$counter);
|
||||
$str_remove=sprintf("import_remove('%s','%s','%s');",
|
||||
$_REQUEST['PHPSESSID'],
|
||||
dossier::id(),
|
||||
$counter);
|
||||
|
||||
echo '<td><input type="button" value="Modifier" onClick="'.$str_update.'">';
|
||||
echo '<input type="button" name="trashit" value="Effacer.."'.
|
||||
' onClick="'.$str_remove.'" >'.
|
||||
'</td><tr/>';
|
||||
}
|
||||
if ($p_form == 'remove' ) {
|
||||
$str_notconfi=sprintf("import_not_confirmed('%s','%s','%s');",
|
||||
$_REQUEST['PHPSESSID'],
|
||||
dossier::id(),
|
||||
$counter);
|
||||
|
||||
echo '<td><input type="button" value="Enlever" onClick="'.$str_notconfi.'"'.
|
||||
'></td><tr/>';
|
||||
}
|
||||
if ($p_form == 'remove' )
|
||||
echo '<td><input type="submit" value="Enlever"></td><tr/>';
|
||||
|
||||
echo '</table>';
|
||||
|
||||
}
|
||||
/*!\brief Remove the record from the transfert list, the data are in $_POST
|
||||
* import_tmp.status is set to n for new
|
||||
*
|
||||
*/
|
||||
function RemoveCSV($cn)
|
||||
{
|
||||
$sql="update import_tmp set poste_comptable=null,status='n' where code='".$_POST['code']."'";
|
||||
ExecSql($cn,$sql);
|
||||
}
|
||||
|
||||
/*!\brief Verify the import
|
||||
*/
|
||||
|
||||
|
|
@ -161,8 +170,10 @@ function VerifImport($p_cn){
|
|||
// include javascript for popup
|
||||
echo JS_SEARCH_CARD;
|
||||
echo JS_CONCERNED_OP;
|
||||
echo JS_AJAX_FICHE;
|
||||
echo JS_PROTOTYPE_JS;
|
||||
while($val = pg_fetch_array($Res)){
|
||||
echo '<form METHOD="POST" action="import.php?action=verif">';
|
||||
echo '<form METHOD="POST" id="form_'.$i.'"action="import.php?action=verif">';
|
||||
echo dossier::hidden();
|
||||
ShowBox($val,$i,$p_cn,'form');
|
||||
echo '</form>';
|
||||
|
|
@ -176,6 +187,7 @@ function VerifImport($p_cn){
|
|||
* \param $periode user's periode
|
||||
*/
|
||||
function ConfirmTransfert($p_cn,$periode){
|
||||
|
||||
$sql = "select to_char(p_start,'DD-MM-YYYY') as p_start,to_char(p_end,'DD-MM-YYYY') as p_end".
|
||||
" from parm_periode where p_id = '".$periode."'";
|
||||
$Res=ExecSql($p_cn,$sql);
|
||||
|
|
@ -204,14 +216,14 @@ function ConfirmTransfert($p_cn,$periode){
|
|||
$i=1;
|
||||
while($val = pg_fetch_array($Res)){
|
||||
|
||||
echo '<form method="post" action="import.php">';
|
||||
echo '<form method="post" id="form_'.$i.'" action="import.php">';
|
||||
echo dossier::hidden();
|
||||
echo '<input type="hidden" name="action" value="remove">';
|
||||
ShowBox($val,$i,$p_cn,'remove');
|
||||
echo '</form>';
|
||||
$i++;
|
||||
}
|
||||
echo '<form method="post" action="import.php">';
|
||||
echo '<form method="post" id="form_'.$i.'" action="import.php">';
|
||||
echo dossier::hidden();
|
||||
echo '<input type="hidden" name="action" value="transfer">';
|
||||
echo '<input type="submit" name="sub" value="Commencer le transfert">';
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
// Bank ING
|
||||
//-----------------------------------------------------
|
||||
$row=1;
|
||||
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
|
||||
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE) {
|
||||
$num = count($data);
|
||||
for ($c=0; $c < $num; $c++) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue