33require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
40 parent::__construct($p_cn, $p_init);
41 $this->ledger_type=
'FIN';
54 throw new Exception(
"Array empty");
62 if (isset($mt)&&$this->
db->count_sql(
'select jr_mt from jrn where jr_mt=$1', array($mt))!=0)
63 throw new Exception(_(
'Double Encodage'), 5);
67 throw new Exception(_(
'Accès interdit'), 20);
72 if ($this->
db->count()==0)
73 throw new Exception(
"Ce journal n'a pas de compte en banque, allez dans paramètre->journal pour régler cela");
75 $fBank=
new Fiche($this->
db, $bank_id);
77 if (trim($bank_accounting)==
'')
78 throw new Exception(
'Le poste comptable du compte en banque de ce journal est invalide');
83 throw new Exception(
'Le poste comptable du compte en banque de ce journal est invalide');
84 if ($chdate!=1&&$chdate!=2)
85 throw new Exception(
'Le choix de date est invalide');
91 throw new Exception(
'Date invalide', 2);
104 throw new Exception(_(
'Date et periode ne correspondent pas'), 6);
110 throw new Exception(_(
'Periode fermee'), 6);
120 throw new Exception(_(
'Vous utilisez le mode strict la dernière operation est à la date du ')
121 .$last_date._(
' vous ne pouvez pas encoder à une date antérieure'), 15);
132 for (
$i=0;
$i<$nb_item;
$i++)
137 if (
isNumber(${
'e_other'.$i.
'_amount'})==0)
138 throw new Exception(
'La fiche '.${
'e_other'.$i}.
'a un montant invalide ['.${
'e_other'.$i.
'_amount'}.
']',
145 $fiche->get_by_qcode(${
'e_other'.$i});
147 throw new Exception(
'La fiche '.${
'e_other'.$i}.
'n\'a pas de poste comptable', 8);
151 if (strpos($sposte,
',')!=0)
153 $array=explode(
',', $sposte);
162 if (
$poste->load()==
false)
164 throw new Exception(
'Pour la fiche '.${
'e_other'.$i}.
' le poste comptable ['.
$poste->id.
'n\'existe pas',
169 $fiche->get_by_qcode(${
'e_other'.$i});
171 throw new Exception(
'La fiche '.${
'e_other'.$i}.
'n\'est pas accessible à ce journal', 10);
175 if (
isDate(${
'dateop'.$i})==
null)
177 throw new Exception(
'Date invalide', 2);
190 throw new Exception(_(
'Date et periode ne correspondent pas'), 6);
196 throw new Exception(_(
'Periode fermee'), 6);
205 if ($last_date!=
null&&
cmpDate(${
'dateop'.$i}, $last_date)<0)
206 throw new Exception(_(
'Vous utilisez le mode strict la dernière operation est à la date du ')
207 .$last_date._(
' vous ne pouvez pas encoder à une date antérieure'), 15);
214 throw new Exception(
'Il n\'y a aucune opération', 12);
220 $diff=bcsub($last_sold,$first_sold,2);
223 if ($first_sold!=0||$last_sold!=0)
227 throw new Exception(sprintf(_(
'Le montant de l\'extrait est incorrect,'.
228 " solde donné [ %s ]".
229 " solde calculé [%s] , différence de [%s]"), $last_sold, $calc,
253 $str_add_button_tiers=
"";
262 list ($l_date_start, $l_date_end)=
$pPeriode->get_date_limit(
$g_user->get_periode());
270 $r.=dossier::hidden();
271 $f_legend=
'Banque, caisse';
274 $Date=
new IDate(
"e_date", $op_date);
275 $Date->setReadOnly($pview_only);
276 $f_date=$Date->input();
286 $period->value=$l_user_per;
288 $period->name=
'periode';
291 $l_form_per=$period->input();
295 if (
$e->getCode()==1)
297 throw new Exception(_(
"Aucune période ouverte"));
301 $f_period=
"Période comptable $label".$l_form_per;
306 $onchange=
"update_bank();ajax_saldo('first_sold');update_name();update_row('fin_item');show_ledger_fin_currency();";
309 $onchange.=
'get_last_date();';
311 $onchange.=
'update_pj();';
313 $add_js=
'onchange="'.$onchange.
'"';
316 throw new Exception(_(
'Pas de journal disponible'));
324 $f_bank=
'<span id="bkname">'.$this->get_bank_name().
'</span>';
325 if ($this->bank_id==
"")
327 echo
h2(
"Journal de banque non configuré ".$this->
get_name(),
' class="error"');
328 echo
'<span class="error"> vous devez donner à ce journal un compte en banque (fiche), modifiez dans CFGLED</span>';
332 $f_legend_detail=
'Opérations financières';
342 $wPJ=
new IText(
'e_pj');
343 $wPJ->readonly=
false;
345 $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
347 $f_extrait=$wPJ->input().HtmlInput::hidden(
'e_pj_suggest', $default_pj);
350 $first_sold=(isset($first_sold))?$first_sold:
"";
351 $wFirst=
new INum(
'first_sold', $first_sold);
353 $last_sold=isset($last_sold)?$last_sold:
"";
354 $wLast=
new INum(
'last_sold', $last_sold);
356 $max=(isset($nb_item))?$nb_item:$min_article;
367 $tiers=(isset(${
"e_other".$i}))?${
"e_other".$i}:
"";
369 $tiers_amount=(isset(${
"e_other$i".
"_amount"}))?round(${
"e_other$i".
"_amount"}, 2):0;
371 $tiers_comment=(isset(${
"e_other$i".
"_comment"}))?${
"e_other$i".
"_comment"}:
"";
373 $operation_date=
new IDate(
"dateop".
$i);
374 $operation_date->value=(isset(${
'dateop'.$i}))?${
'dateop'.$i}:
"";
375 $array[
$i][
'dateop']=$operation_date->input();
376 ${
"e_other$i".
"_amount"}=(isset(${
"e_other$i".
"_amount"}))?${
"e_other$i".
"_amount"}:0;
380 $W1->name=
"e_other".$i;
381 $W1->id=
"e_other".$i;
385 $W1->set_dblclick(
"fill_ipopcard(this);");
386 $W1->set_attribute(
'ipopup',
'ipopcard');
389 $W1->set_attribute(
'label',
'e_other_name'.
$i);
391 $W1->set_attribute(
'typecard',
'filter');
393 $W1->set_callback(
'filter_card');
394 $W1->set_function(
'fill_data');
395 $W1->javascript=sprintf(
' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
396 $W1->readonly=$pview_only;
399 $array[
$i][
'card_add']=($add_card==TRUE)?$this->
add_card(
"deb", $W1->id):
"";
407 $card_name=$this->
db->get_value(
"Select ad_value from fiche_detail where ad_id=$1 and f_id=$2",
411 $wcard_name=
new IText(
"e_other_name".
$i, $card_name);
412 $wcard_name->id=$wcard_name->name;
413 $wcard_name->readOnly=
true;
414 $array[
$i][
'cname']=$wcard_name->input();
417 $wComment=
new IText(
"e_other$i".
"_comment", $tiers_comment);
418 $wComment->style=
'class="input_text label_item"';
420 $wComment->setReadOnly($pview_only);
421 $array[
$i][
'comment']=$wComment->input();
423 $wAmount=
new INum(
"e_other$i".
"_amount", $tiers_amount);
426 $wAmount->setReadOnly($pview_only);
427 $array[
$i][
'amount']=$wAmount->input();
429 ${
"e_concerned".$i}=(isset(${
"e_concerned".$i}))?${
"e_concerned".$i}:
""
431 $wConcerned=
new IConcerned(
"e_concerned".
$i, ${
"e_concerned".$i});
432 $wConcerned->tiers=
"e_other".$i;
434 $wConcerned->amount_id=
"e_other".$i.
"_amount";
436 $wConcerned->paid=
'paid';
437 $array[
$i][
'concerned']=$wConcerned->input();
441 require_once NOALYSS_TEMPLATE.
'/form_ledger_fin.php';
442 $r.=ob_get_contents();
482 list ($l_date_start, $l_date_end)=
$pPeriode->get_date_limit();
485 $r.=
'<fieldset><legend>'._(
"Banque, caisse").
' </legend>';
486 $r.=
'<div id="jrn_name_div">';
487 $r.=
'<h1 id="jrn_name" style="display:inline">'.$this->get_name().
'</h1>';
489 $r.=
'<TABLE width="100%">';
494 $r.=
'<td> Date : </td><td>'.$e_date;
498 $r.=
"Période comptable </td><td>";
499 $r.=$l_date_start.
' - '.$l_date_end;
505 $r.=
'<td> Journal </td>';
515 $fBank=
new Fiche($this->
db, $bk_id);
518 $filter_year=
" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice.
"')";
522 $deb=$asolde[
'debit'];
523 $cred=$asolde[
'credit'];
527 $r.=
"<TR><td colspan=\"4\"> Banque ";
528 $r.=$e_bank_account_label;
534 $r.=
'<div class="myfieldset"><h1 class="legend">'._(
"Extrait de compte").
'</h1>';
542 $r.=
tr(
'<td>'._(
"Numéro d'extrait").
' </td>'.
td(
h($e_pj)));
543 $r.=
'<tr><td >'._(
"Solde début extrait").
' </td>';
544 $r.=
'<td style="num">'.nbm($first_sold).
'</td></tr>';
545 $r.=
'<tr><td>'._(
"Solde fin extrait").
' </td>';
546 $r.=
'<td style="num">'.nbm($last_sold).
'</td></tr>';
549 $r.=
'<h1 class="legend">Opérations financières</h1>';
553 $r.=
'<TABLE style="width:100%" id="fin_item">';
556 $r.=
'<th>'._(
"Date").
'</th>';
557 $r.=
"<th style=\"width:auto;text-align:left\" colspan=\"2\">"._(
"Nom").
"</th>";
558 $r.=
"<th style=\"text-align:left\" >"._(
"Commentaire").
"</th>";
559 $r.=
"<th style=\"text-align:right\">"._(
"Montant").
"</th>";
560 $r.=
'<th colspan="2">'._(
"Op. Concernée(s)").
'</th>';
566 $a_anc=
$anc->get_list();
569 $r.=
'<th colspan="'.$x.
'">'._(
'Compt. Analytique').
'</th>';
580 for (
$i=0;
$i<$nb_item;
$i++)
583 $tiers=(isset(${
"e_other".$i}))?${
"e_other".$i}:
""
589 $tiers_amount=round(${
"e_other$i".
"_amount"}, 2);
591 $tiers_comment=
h(${
"e_other$i".
"_comment"});
594 $fTiers->get_by_qcode(
$tiers);
600 $r.=
td(${
"dateop".$i});
601 $r.=
"<td>".${
'e_other'.$i}.
"</TD>";
603 $r.=
'<TD style="width:25%;border-bottom:1px dotted grey;">';
607 $r.=
'<td style="width:40%">'.$tiers_comment.
'</td>';
609 $r.=
'<td class="num">'.nbm($tiers_amount).
'</td>';
611 $r.=
'<td style="text-align:center">';
612 if (${
"e_concerned".$i}!=
'')
614 $jr_internal=$this->
db->get_array(
"select jr_internal from jrn where jr_id in (".${
"e_concerned".$i}.
")");
616 for ($x=0; $x<count($jr_internal); $x++)
618 $r.=$comma.HtmlInput::detail_op(${
"e_concerned".$i}, $jr_internal[$x][
'jr_internal']);
634 $r.=$anc_op->display_form_plan(
$p_array, $null, $p_mode,
$i, $tiers_amount);
644 if ($acc_currency->get_id()!=0)
647 $solde=$fBank->get_bk_balance_currency();
648 $cur=$acc_currency->get_code();
649 $cur_rate=$acc_currency->get_rate_date(
$e_date);
654 td(_(
"Ancien solde")).
659 td(_(
"Nouveau solde")).
660 td(
nbm($new_solde).$cur,
' class="num"')
671 td(_(
"Nouveau solde")).
679 $cur=$acc_currency->get_code();
683 td(_(
"Ancien solde")).
688 td(_(
"Nouveau solde")).
689 td(
nbm($new_solde).$cur,
' class="num"')
700 $file->setAlertOnSize(
true);
701 $r.=
"<br>"._(
"Ajoutez une pièce justificative").
" ";
708 $r.=dossier::hidden();
721 $r.=dossier::hidden();
723 for (
$i=0;
$i<$nb_item;
$i++)
725 $tiers=(isset(${
"e_other".$i}))?${
"e_other".$i}:
"";
758 $fBank=
new Fiche($this->
db, $bank_id);
764 if (strpos($sposte,
',')!=0)
766 $array=explode(
',', $sposte);
788 $filter_year=
" j_tech_per in (select p_id from parm_periode where p_exercice='".$exercice.
"')";
790 $deb=$asolde[
'debit'];
791 $cred=$asolde[
'credit'];
804 $ret=
'<table class="result" >';
805 $ret.=
tr(
th(_(
'Date')).
th(_(
'n° interne')).
th(_(
'Quick Code'))
806 .
th(_(
'Nom')).
th(_(
'Libellé')).
th(_(
'Montant'),
' style="text-align:right"'));
815 $currency_rate=$acc_currency->get_rate_date(
$e_date);
819 printf(
"<p> currency_id %s </p>",$this->currency_id);
820 printf(
"<p> rate %s </p>", $currency_rate);
823 for (
$i=0;
$i<$nb_item;
$i++)
834 $currency_rate=$acc_currency->get_rate_date(
$e_date);
837 if ($chdate==2&&$get_solde)
849 $filter_year=
" j_tech_per in (select p_id from parm_periode where p_exercice='".
855 $fPoste->get_by_qcode(${
"e_other$i"});
858 $amount_input=${
"e_other$i".
"_amount"}=round(${
"e_other$i".
"_amount"}, 2);
859 $amount_eur=bcdiv($amount_input, $currency_rate);
865 $seq=$this->
db->get_next_seq(
's_grpt');
871 if (strpos($sposte,
',')!=0)
873 $array=explode(
',', $sposte);
874 if (${
"e_other$i".
"_amount"}<0)
885 $acc_operation->poste=$poste_val;
886 $acc_operation->amount=bcmul($amount_eur, -1);
887 $acc_operation->grpt=
$seq;
888 $acc_operation->jrn=
$p_jrn;
889 $acc_operation->type=
'd';
898 $acc_operation->periode=$tperiode;
899 $acc_operation->qcode=${
"e_other".$i};
900 $j_id_currency=$acc_operation->insert_jrnx();
904 $operation_currency->oc_amount=$amount_input;
905 $operation_currency->oc_vat_amount=0;
906 $operation_currency->oc_price_unit=0;
907 $operation_currency->j_id=$j_id_currency;
908 $operation_currency->insert();
915 if (strpos($sposte,
',')!=0)
917 $array=explode(
',', $sposte);
918 if (${
"e_other$i".
"_amount"}<0)
928 $acc_operation->poste=$poste_val;
929 $acc_operation->amount=$amount_eur;
930 $acc_operation->grpt=
$seq;
931 $acc_operation->jrn=
$p_jrn;
932 $acc_operation->type=
'd';
933 $acc_operation->periode=$tperiode;
934 $acc_operation->qcode=$e_bank_account;
935 $j_id=$acc_operation->insert_jrnx();
939 $operation_currency->oc_amount=$amount_input;
940 $operation_currency->oc_vat_amount=0;
941 $operation_currency->oc_price_unit=0;
942 $operation_currency->j_id=
$j_id;
943 $operation_currency->insert();
945 if (
sql_string(${
"e_other$i".
"_comment"})==
null)
948 $comment=sprintf(_(
" compte : %s a %s "), $fBank->strAttribut(
ATTR_DEF_NAME),
954 $comment=strip_tags(${
'e_other'.$i.
'_comment'});
959 $acc_operation->jrn=
$p_jrn;
960 $acc_operation->amount=abs($amount_eur);
962 $acc_operation->desc=$comment;
963 $acc_operation->grpt=
$seq;
964 $acc_operation->periode=$tperiode;
965 $acc_operation->mt=$mt;
967 $acc_operation->pj=
'';
969 $acc_operation->currency_rate=$currency_rate;
970 $acc_operation->currency_rate_ref=$currency_rate;
973 $acc_operation->pj=$e_pj.str_pad($idx_operation, 3, 0, STR_PAD_LEFT);
976 $acc_operation->pj=$e_pj;
978 $jr_id=$acc_operation->insert_jrn();
980 $this->
db->exec_sql(
'update jrn set jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj,
$jr_id));
983 if (trim(${
"e_concerned".$i})!=
"")
985 if (strpos(${
"e_concerned".$i},
',')!=0)
987 $aRapt=explode(
',', ${
"e_concerned".$i});
988 foreach ($aRapt as $rRapt)
997 $rec->insert($rRapt);
1001 $oppaid->set_id($rRapt);
1002 $oppaid->set_paid();
1004 catch (Exception
$ex)
1007 echo _(
'Attention , erreur Acc_Ledger_Fin::insert , coche paiement');
1013 if (
isNumber(${
"e_concerned".$i})==1)
1017 $rec->insert(${
"e_concerned$i"});
1021 $oppaid->set_id(${
"e_concerned".$i});
1022 $conc_amount=$oppaid->get_amount();
1023 if ($conc_amount==$acc_operation->amount)
1025 $oppaid->set_paid();
1028 catch (Exception
$ex)
1031 echo _(
'Attention , erreur Acc_Ledger_Fin::insert , coche paiement');
1037 $this->grpt_id=
$seq;
1047 $op->set_currency_rate($currency_rate);
1048 $op->oa_group=$this->
db->get_next_seq(
"s_oa_group");
1049 $op->j_id=$j_id_currency;
1065 .td(${
"e_other".$i.
"_comment"})
1066 .
td(
nbm(${
"e_other$i".
"_amount"}),
'class="num"');
1067 $class=(
$i%2==0)?
' class="even" ':
' class="odd" ';
1074 if (isset($_FILES[
'pj']))
1075 $oid=$this->
db->save_receipt(
$seq);
1081 $this->
db->exec_sql(
"update jrn set jr_pj=$1 , jr_pj_name=$2,
1082 jr_pj_type=$3 where jr_grpt_id=$4",
1083 array($oid, $_FILES[
'pj'][
'name'], $_FILES[
'pj'][
'type'],
$seq));
1094 catch (Exception
$e)
1096 $r=
'<span class="error">'.
1097 'Erreur dans l\'enregistrement '.
1098 __FILE__.
':'.__LINE__.
' '.
1100 $this->
db->rollback();
1102 throw new Exception(
$r);
1104 $this->
db->commit();
1105 if ($acc_currency->get_id()==0)
1108 $r.=sprintf(
"<br>"._(
"Ancien solde %s %s"),
nbm(
$solde), $acc_currency->get_code());
1109 $new_solde=bcadd($new_solde,
$amount);
1110 $r.=sprintf(
"<br>"._(
"Nouveau solde %s %s"),
nbm($new_solde), $acc_currency->get_code());
1115 $solde_cur=$fBank->get_bk_balance_currency();
1117 $r.=sprintf(
"<br>"._(
"Ancien solde %s %s"),
nbm($solde_cur), $acc_currency->get_code());
1118 $new_solde=bcadd($solde_cur,
$amount);
1119 $r.=sprintf(
"<br>"._(
"Nouveau solde %s %s"),
nbm($new_solde), $acc_currency->get_code());
1130 $this->bank_id=$this->
db->get_value(
'select jrn_def_bank from jrn_def where jrn_def_id=$1', array($this->
id));
1131 $fBank=
new Fiche($this->
db, $this->bank_id);
1135 return $e_bank_qcode.$e_bank_name.$e_bank_account;
1143 $bank_id=$this->
db->get_value(
'select jrn_def_bank from jrn_def where jrn_def_id=$1', array($this->
id));
1144 if (empty($bank_id))
return -1;
1153 $a=$this->
db->get_value(
'select jrn_def_num_op from jrn_def where jrn_def_id=$1', array($this->
id));
1169 $sql=
"INSERT INTO quant_fin(qf_bank, jr_id, qf_other, qf_amount,j_id)
1170 VALUES ($1, $2, $3, $4,$5);";
1172 $this->
db->exec_sql(
$sql, array($p_bankid, $p_jrid, $p_otherid, round($p_amount, 2), $p_j_id_currency));
h2($p_string, $p_class="", $raw="")
th($p_string, $p_extra='', $raw='')
noalyss_strlentrim($p_string)
tr($p_string, $p_extra='')
record_log($p_message)
Record an error message into the log file of the server.
sql_string($p_string)
Fix the problem with the quote char for the database.
td($p_string='', $p_extra='')
surround the string with td
nbm($p_number, $p_dec=2)
format the number with a sep.
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
alert($p_msg, $buffer=false)
alert in javascript
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
catch(Exception $e) $exercice
Manage the account from the table jrn, jrnx or tmp_pcmn.
display currency , convert to euro , and save them if used.
the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger
input($p_array=null, $notused=0)
display a form to enter an FIN operation
verify_operation($p_array)
Verify that the data are correct before inserting or confirming.
get_bank_name()
return a string with the bank account, name and quick_code
__construct($p_cn, $p_init)
insert_quant_fin($p_bankid, $p_jrid, $p_otherid, $p_amount, $p_j_id_currency)
insert into the quant_fin table
numb_operation()
return true is we numbere each operation
get_bank()
find and FICHE.F_ID of the bank or -1 if not found
confirm($p_array, $p_nothing=0)
show the result of the array to confirm before inserting
$currency_id
!< default number of rows by default 10
get_currency()
returns the code iso of the default currency for this ledger
$nb
!< type of the ledger ACH ODS FIN VEN or GL
inc_seq_pj()
increment the sequence for the pj
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
get_name()
Return the name of a ledger.
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
$row
!< database connextion
is_closed($p_periode)
check if the current ledger is closed
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
update_internal_code($p_internal)
get_last_date()
get the date of the last operation
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
check_strict()
Check if a Dossier is using the strict mode or not.
guess_pj()
guess what the next pj should be
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
this class is used to show the form for entering an operation only FOR analytic operation to save it,...
Concerns the Analytic plan (table plan_analytique)
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
This class handles only the numeric input, the input will call a javascript to change comma to period...
Generate the form for the periode Data Members.
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
ORM abstract of the table public.operation_currency.
For the periode tables parm_periode and jrn_periode.
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
if(sizeof($array)==0) $pPeriode
create_script($p_string)
create the HTML for adding the script tags around of the script
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...
for($i=0;$i< $nb_jrn;$i++) $deb