27 require_once
'class_format_bank_sql.php';
28 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger_fin.php';
29 require_once NOALYSS_INCLUDE.
'/class/class_periode.php';
30 require_once
'class_temp_bank_sql.php';
41 $r=HtmlInput::extension().Dossier::hidden();
57 for ($i=0; $i<count(
$array); $i++)
68 if (isset(
$check[$idx+1][
'count']))
70 $check[$idx+1][
'count'] ++;
78 $error.=_(
"Il manque la colonne pour les dates").
" \n";
80 $error.=_(
"Il manque la colonne pour les montants").
" \n";
84 if ($row[
'value']==-1)
86 if (isset($row[
'count'])&&$row[
'count']>1)
87 $error.=$row[
'label'].
" a été donné ".$row[
'count'].
" fois\n";
99 $ret=$cn->exec_sql(
'select a.id,to_char(i_date,\'DD.MM.YYYY HH24:MI\') as str_date,format_name,i_date
100 from importbank.import as a
101 left join importbank.format_bank as b on (format_bank_id=b.id)
102 order by i_date desc');
103 $link=
'?'.Dossier::get().
'&plugin_code='.
$_REQUEST[
'plugin_code'].
104 '&sb=list&sa='.$_REQUEST[
'sa'].
"&ac=".
$_REQUEST[
'ac'];
106 $status=$cn->prepare(
'status',
107 'select count(*) from importbank.temp_bank where import_id=$1 and status=$2');
109 require_once(
'template/show_import.php');
115 static function delete($p_array)
119 $a=$p_array[
's_del'];
120 for ($i=0; $i<count(
$a); $i++)
122 $cn->exec_sql(
'delete from importbank.import where id=$1',
134 $filter=
new ISelect(
'fil_status');
136 array(
'value'=>0,
'label'=>_(
'Tous')),
137 array(
'value'=>1,
'label'=>_(
'Nouveau')),
138 array(
'value'=>2,
'label'=>_(
'Transfèré')),
139 array(
'value'=>3,
'label'=>_(
'Attente')),
140 array(
'value'=>4,
'label'=>_(
'Erreur')),
141 array(
'value'=>5,
'label'=>_(
'Effacer'))
143 $filter->javascript=
' onchange="submit(this)"';
145 $filter->selected=HtmlInput::default_value(
'fil_status', 0, $_GET);
148 $array=$cn->get_array(
'select a.id as id,to_char(i_date,\'DD.MM.YYYY HH24:MI\') as i_date,format_name,jrn_def_id
149 from importbank.import as a
150 left join importbank.format_bank as b on (format_bank_id=b.id)
151 where a.id=$1', array($p_id));
153 $ret=$cn->exec_sql(
" SELECT id ,ref_operation,tp_date, amount,
154 case when status='N' then 'Nouveau'
155 when status='T' then 'Transfèré'
156 when status='W' then 'Attente'
157 when status='E' then 'ERREUR'
158 when status='D' then 'Effacer'
164 tp_third, tp_extra,is_checked
165 FROM importbank.temp_bank
166 where import_id=$1 $sql_filter
167 order by tp_date,ref_operation,amount", array($p_id));
169 if ( isset (
$array[0][
'jrn_def_id']) )
171 $jrn_name=$cn->get_value(
'select jrn_def_name from jrn_def where jrn_def_id=$1',
172 array(
$array[0][
'jrn_def_id']));
173 $jrn_account=$cn->get_value(
"select ad_value from fiche_detail
174 where ad_id=1 and f_id=(select jrn_Def_bank from jrn_def where jrn_def_id=$1) "
175 , array(
$array[0][
'jrn_def_id']));
178 $jrn_name=_(
"Format effacé");
181 require_once(
'template/show_list.php');
197 $style=
"background-color:red;color:white";
200 $style=
"background-color:orange;color:white";
203 $style=
"background-color:darkgreen;color:white";
206 $style=
"background-color:grey;color:red";
209 $style=
"background-color:white;color:blue";
214 $style=
'style="'.$style.
'"';
225 $cn->exec_sql(
'delete from importbank.temp_bank where import_id=$1
226 and status=\'D\'', array($p_array[
'id']));
244 $led_id=$cn->get_value(
'select jrn_def_id
245 from importbank.format_bank as fb
246 join importbank.import as imp on (format_bank_id = fb.id)
247 where imp.id=$1', array($p_array[
'id']));
249 $fin_ledger=
new Acc_Ledger_Fin($cn, $led_id);
250 $card_bank=$fin_ledger->get_bank();
251 $quickcode_bank=$cn->get_value(
'select ad_value from fiche_detail where f_id=$1 and ad_id=$2',
252 array($card_bank, ATTR_DEF_QUICKCODE));
253 $account_bank=$cn->get_value(
'select ad_value from fiche_detail where f_id=$1 and ad_id=$2',
254 array($card_bank, ATTR_DEF_ACCOUNT));
255 $bank_name=$fin_ledger->get_name();
259 $sql=
"select id from importbank.temp_bank where import_id=$1 and status='W'";
261 $ResAll=$cn->exec_sql(
$sql, array($p_array[
'id']));
262 $Max=Database::num_row($ResAll);
264 for ($i=0; $i<$Max; $i++)
266 $val=Database::fetch_array($ResAll, $i);
268 $row=
new Temp_Bank_Sql($cn, $val[
'id']);
270 if (
$row->f_id==null||
$row->f_id==
'')
273 self::transfert_error(
$row->id,
'Aucune fiche donnée');
278 $f=
new Fiche($cn,
$row->f_id);
279 $poste_comptable=
$f->strAttribut(ATTR_DEF_ACCOUNT);
280 $quick_code=
$f->strAttribut(ATTR_DEF_QUICKCODE);
283 if ($poste_comptable==NOTFOUND||strlen(trim($poste_comptable))==0)
286 self::transfert_error(
$row->id,
287 _(
'Poste comptable de la fiche est incorrecte'));
290 if (self::check_date(
$row->tp_date)==
false)
293 self::transfert_error(
$row->id, _(
'Date hors des limites'));
296 $err=self::is_closed(
$row->tp_date, $led_id);
299 self::transfert_error(
$row->id,
300 $err._(
' - Date hors des journaux'));
304 if ( strpos($poste_comptable,
',') != 0 ) {
305 list($poste_debit,$poste_credit) =explode(
',',$poste_comptable);
306 $poste_comptable=(
$row->amount > 0 ) ? $poste_debit: $poste_credit;
310 $seq=$cn->get_next_seq(
's_grpt');
311 $p_user=$_SESSION[
'g_user'];
313 $acc_op=
new Acc_Operation($cn);
314 $acc_op->amount=
$row->amount;
317 $acc_op->date=
$row->tp_date;
318 $acc_op->user=$p_user;
319 $acc_op->poste=$account_bank;
321 $acc_op->jrn=$led_id;
323 $acc_op->f_id=$card_bank;
324 $acc_op->qcode=$quickcode_bank;
325 $acc_op->mt=microtime(
true);
326 $r=$acc_op->insert_jrnx();
330 $acc_op->poste=$poste_comptable;
331 $acc_op->amount=
$row->amount;
332 $acc_op->f_id=
$row->f_id;
333 $acc_op->qcode=$quick_code;
334 $r=$acc_op->insert_jrnx();
336 $acc_op->desc=
$row->tp_third.
" ".
$row->libelle.
" ".
$row->tp_extra;
337 $jr_id=$acc_op->insert_jrn();
339 $internal=$fin_ledger->compute_internal_code($seq);
341 $Res=$cn->exec_sql(
"update jrn set jr_internal=$1 where jr_id = $2",
342 array($internal, $jr_id));
344 $fin_ledger->insert_quant_fin($card_bank, $jr_id,
$row->f_id,
348 if (trim(
$row->tp_rec)!=
'')
350 $acc_reconc=
new Acc_Reconciliation($cn);
351 $acc_reconc->set_jr_id($jr_id);
352 $acc_reconc->insert(
$row->tp_rec);
355 $sql2=
"update importbank.temp_bank set status = 'T',tp_error_msg=null where id=$1";
356 $Res2=$cn->exec_sql($sql2, array(
$row->id));
362 echo
'<span class="error">'.
363 'Erreur dans '.__FILE__.
':'.__LINE__.
364 ' Message = '.$e->getMessage().
377 $cn->exec_sql(
'update importbank.temp_bank set status=$1,tp_error_msg=$2 where id=$3',
378 array(
'E', $message,
$id));
388 $sql=
"select count(*) from parm_periode where p_start <= to_date($1,'DD.MM.YYYY') and p_end >= to_date($1,'DD.MM.YYYY') ";
409 return "Période fermée";
414 $err=$e->getMessage();
427 $ledger=
new Acc_Ledger_Fin($cn, $p_ledger);
431 alert(_(
'Journal financier mal configuré'));
437 $bank_card=
new Fiche($cn);
438 $bank_card->id=$bank;
442 $bank_accounting=$bank_card->strAttribut(ATTR_DEF_ACCOUNT);
443 $exist=$cn->get_value(
'
444 select count(*) from tmp_pcmn
447 ', array($bank_accounting)
459 $id=HtmlInput::default_value_request(
"id", 0);
460 $action=HtmlInput::default_value_request(
"select_action", 0);
461 $cn=Dossier::connect();
463 throw new Exception(_(
"Donnée invalide"));
470 $suppress_reconcile = 3;
471 $accept_reconcile = 4;
482 $fiche_code=HtmlInput::default_value_request(
"fiche1000",
"");
483 $fiche_code=trim($fiche_code);
484 if ($fiche_code ==
"" ) {
485 throw new Exception(_(
"Donnée invalide").
"\$fiche_code");
489 $fiche->get_by_qcode($fiche_code,
false);
491 throw new Exception(_(
"Fiche non trouvée"));
494 $cn->exec_sql(
"update importbank.temp_bank set f_id = $1 , "
495 .
" status = 'W' , is_checked = 0"
497 .
" import_id = $2 and "
498 .
" status in ('N','W','E','D') and"
509 $cn->exec_sql(
"update importbank.temp_bank set "
510 .
" status = 'N' , is_checked = 0 , f_id = null"
512 .
" import_id = $1 and "
513 .
" status <> 'T' and"
521 $cn->exec_sql(
"update importbank.temp_bank set "
522 .
" status = 'D' , is_checked = 0"
524 .
" import_id = $1 and "
525 .
" status <> 'T' and"
534 $cn->exec_sql(
"update importbank.temp_bank set "
535 .
" status = 'N' , is_checked = 0"
537 .
" import_id = $1 and "
538 .
" status = 'D' and"
542 case $suppress_reconcile:
548 from importbank.suggest_bank
550 temp_bank_id in (select id
551 from importbank.temp_bank
553 is_checked=1 and import_id=$1)";
556 update importbank.temp_bank set is_checked=0
558 is_checked=1 and import_id=$1";
562 case $accept_reconcile:
567 update importbank.temp_bank set tp_rec = jr_id::text,
569 f_id=suggest_bank.f_id,
571 from importbank.suggest_bank
572 where temp_bank_id=temp_bank.id
573 and temp_bank.import_id=$1
574 and temp_bank.is_checked=1
575 and temp_bank.id not in (select temp_bank_id from importbank.suggest_bank group by temp_bank_id having count(temp_bank_id) > 1)
579 update importbank.temp_bank set is_checked=0
581 is_checked=1 and import_id=$1";
586 throw new Exception(_(
"action impossible"));
598 $cn=Dossier::connect();
601 insert into importbank.suggest_bank (temp_bank_id,jr_id,f_id)
602 select distinct tb.id, jrn.jr_id,jrnx.f_id
606 importbank.temp_bank as tb ,
609 jrnx.j_grpt=jrn.jr_grpt_id
610 and j_date > tb.tp_date - interval '90 days'
611 and j_date < tb.tp_date + interval '90 days'
612 and jrn_info.jr_id = jrn.jr_id
615 and jrnx.f_id is not null
616 and ( (amount < 0 and j_debit = false ) or (amount > 0 and j_debit=true))
617 and tb.id not in (select temp_bank_id from importbank.suggest_bank)
618 and jrn_info.id_type in ('OTHER','BON_COMMANDE')
619 and coalesce(jrn_info.ji_value,'') != ''
621 ( position ( lower(jrn_info.ji_value) in lower(tb.libelle)) > 0
622 or position ( lower(jrn_info.ji_value) in lower(tb.tp_extra)) > 0
625 $cn->exec_sql(
$sql,array($p_id));
628 insert into importbank.suggest_bank (temp_bank_id,jr_id,f_id)
629 select distinct tb.id, jr_id,jrnx.f_id
633 importbank.temp_bank as tb
635 jrnx.j_grpt=jrn.jr_grpt_id
636 and j_date > tb.tp_date - interval '80 days'
637 and j_date < tb.tp_date + interval '80 days'
640 and abs(amount) = j_montant
641 and ( (amount < 0 and j_debit = false ) or (amount > 0 and j_debit=true))
642 and jrnx.f_id is not null
643 and tb.id not in (select temp_bank_id from importbank.suggest_bank)
644 and not exists (select jrn_rapt.jr_id from jrn_rapt
645 where jrn_rapt.jr_id = jrn.jr_id
646 or jrn_rapt.jra_concerned =jrn.jr_id)
647 and not exists (select lc.j_id from letter_cred as lc where
648 lc.j_id=jrnx.j_id or lc.jl_id = jrnx.j_id)
649 and not exists (select ld.j_id from letter_deb as ld where
650 ld.j_id=jrnx.j_id or ld.jl_id = jrnx.j_id);
652 $cn->exec_sql(
$sql,array($p_id));
667 $sql_filter=
" and status='N' ";
671 $sql_filter=
" and status='T'";
675 $sql_filter=
" and status='W'";
679 $sql_filter=
" and status='E'";
683 $sql_filter=
" and status='D'";
static transfer_record($p_array)
import row marked to transfer and from the specific import to the database
for($i=0;$i< Database::num_row($ret);$i++) $row
static list_record($p_id)
Show detail of a imported file $p_id is import.id.
static color_status($id)
return the HTML style for the status White : new green : transfered red : error
static check_date($p_date)
check if the date is outside the defined periode
static check_bank_account($p_ledger)
Check that the legder has an card for the bank and this card must also have a valid accounting...
static hidden()
for the form we have here all the hidden variables
if(isset($_POST['remove'])) $array
static selected_action()
Do the same operation for all the selected records , the parameters are found in $_REQUEST.
static is_closed($p_date, $ledger_id)
Check if the date is in a periode and if the ledger is closed or not.
static delete_record($p_array)
delete the record marked as deleted
static show_import()
show the different import
static reconcile_auto($p_id, $all=true)
Try to find the concerned operation, fill the table suggest_bank.
static is_valid_header($array)
check that there is no duplicate among header and we have at least the date and the amount ...
static transfert_error($id, $message)
Update the row with an error message, and change is status to E.
static convert_status_sql($p_param)
Convert the status (0 to 5 to importbank.temp_bank.status which is a letter (N New T Transfered W wai...