21require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
22require_once NOALYSS_INCLUDE.
'/database/jrn_def_sql.class.php';
23require_once NOALYSS_INCLUDE.
'/database/operation_currency_sql.class.php';
76 parent::__construct($p_cn,
$p_id);
83 $this->is_loaded=
false;
87 $this->is_loaded=
true;
105 $this->
db->get_value(
"select currency_id from jrn_def where jrn_def_id=$1",
107 if ( $this->currency_id ==
"") {
108 $this->currency_id=0;
122 throw new Exception(
_(
"Paramètre invalide"));
124 if ($this->
db->exist_sequence(
"s_jrn_pj".$this->id))
126 $ret=$this->
db->get_array(
"select last_value,is_called from s_jrn_pj".$this->
id);
132 if (
$ret[0][
'is_called']==
'f')
138 $this->
db->create_sequence(
"s_jrn_pj".$this->
id);
167 $this->ledger_name=
_(
" Tous les journaux");
168 $this->ledger_type=
"GL";
172 $Res=$this->
db->exec_sql(
"select jrn_def_type from ".
173 " jrn_def where jrn_def_id=".
179 $this->ledger_type=
$ret[
'jrn_def_type'];
180 return $ret[
'jrn_def_type'];
204 $grpt_id=$this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1',
205 array($this->
jr_id));
206 if ($this->
db->count()==0)
210 $this->
db->exec_sql(
'delete from jrnx where j_grpt=$1', array($grpt_id));
211 $this->
db->exec_sql(
'delete from jrn where jr_id=$1',
212 array($this->
jr_id));
222 $str=
'<p class="notice"> '.$p_warning;
223 $str.=
"<ol class=\"notice\">";
224 for (
$i=0;
$i<count($pa_msg);
$i++)
226 $str.=
"<li>".$pa_msg[
$i].
"</li>";
262 throw new Exception(
_(
"this->jr_id is not set ou opération inconnue"));
268 throw new Exception(
_(
'Date invalide').
$p_date);
273 $grp_new=$this->
db->get_next_seq(
's_grpt');
274 $seq=$this->
db->get_next_seq(
"s_jrn");
276 $this->jr_grpt_id=$this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1',
277 array($this->
jr_id));
278 if ($this->
db->count()==0)
279 throw new Exception(
_(
"Cette opération n'existe pas"));
280 $this->jr_internal=$this->
db->get_value(
'select jr_internal from jrn where jr_id=$1',
281 array($this->
jr_id));
282 if ($this->
db->count()==0||trim($this->jr_internal)==
'')
283 throw new Exception(
_(
"Cette opération n'existe pas"));
286 $per=
new Periode($this->
db);
290 if (
$per->is_open()==0)
292 throw new Exception(
_(
'PERIODE FERMEE').
" $p_date ");
297 if ($this->
db->get_value(
"select count(*) from jrn_note where jr_id=$1",[$this->jr_id])>0){
298 $sql=
"update jrn_note set n_text=$2||n_text where jr_id=$1";
301 $sql=
"insert into jrn_note(n_text,jr_id) values ($1,$2)";
308 throw new Exception(__FILE__.__LINE__.
"sql a echoue [ $sql ]");
314 $a_jid=$this->
db->get_array(
"select j_id,j_debit from jrnx where j_grpt=$1",
315 array($this->jr_grpt_id));
318 for (
$l=0;
$l<count($a_jid);
$l++)
324 $sql=
"insert into jrnx (
325 j_date,j_montant,j_poste,j_grpt,
326 j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode
327 ) select to_date($1,'DD.MM.YYYY'),j_montant,j_poste,$2,
328 j_jrn_def,not (j_debit),j_text,$3,$4,$5,
332 where j_id=$6 returning j_id";
339 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
341 $aj_id=$this->
db->fetch(0);
344 $j_id=$aj_id[
'j_id'];
351 $Res=$this->
db->exec_sql(
"INSERT INTO quant_sold(
352 qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
353 qs_vat_code, qs_client, qs_valid, j_id,qs_vat_sided,qs_unit)
354 SELECT $1, qs_fiche, qs_quantite*(-1), qs_price*(-1), qs_vat*(-1),
355 qs_vat_code, qs_client, qs_valid, $2,qs_vat_sided*(-1),qs_unit*(-1)
356 FROM quant_sold where j_id=$3",
361 throw new Exception(__FILE__.__LINE__.
"sql a echoue [ $sql ]");
363 $Res=$this->
db->exec_sql(
"INSERT INTO quant_purchase(
364 qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
365 qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
366 qp_valid, qp_dep_priv,qp_vat_sided,qp_unit)
367 SELECT $1, $2, qp_fiche, qp_quantite*(-1), qp_price*(-1), qp_vat*(-1),
368 qp_vat_code, qp_nd_amount*(-1), qp_nd_tva*(-1), qp_nd_tva_recup*(-1), qp_supplier,
369 qp_valid, qp_dep_priv*(-1),qp_vat_sided*(-1),qp_unit*(-1)
370 FROM quant_purchase where j_id=$3",
375 throw new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]");
378 $this->
db->exec_sql(
"insert into operation_currency (oc_amount,oc_vat_amount,oc_price_unit,j_id) "
379 .
" select oc_amount,oc_vat_amount,oc_price_unit,$j_id from operation_currency where j_id=$1",
382 $jrn_tax_id=$this->
db->exec_sql(
"insert into jrn_tax(j_id,pcm_val,ac_id)
383 select $j_id,pcm_val,ac_id from jrn_tax where j_id=$1 returning jt_id",
389 if ($anc_group_id == 0 ) $anc_group_id=$this->
db->get_next_seq(
's_oa_group');
390 $this->
db->exec_sql(
"
391 insert into operation_analytique (po_id,oa_amount
404 ,case oa_debit when true then false else true end
406 , to_date($2,'DD.MM.YYYY')
411 ,$anc_group_id from operation_analytique
420 $old_receipt=$this->
db->get_row(
"select jr_pj_number,jr_def_id from jrn where jr_id=$1",[$this->
jr_id]);
421 $sql=
"insert into jrn (
436 select $1,jr_def_id,jr_montant,$7,
437 to_date($2,'DD.MM.YYYY'),$3,$4,
438 $5, true,'EXT',currency_id,currency_rate,currency_rate_ref
441 where jr_id=$6 returning jr_id";
444 $reverse_id=$this->
db->get_value(
$sql,
445 array(
$seq,
$p_date, $grp_new, $p_internal,
$per->p_id, $this->jr_id,$p_label));
447 $reverse_accOp->set_id($reverse_id);
448 $reverse_accOp->pj=$old_receipt[
'jr_pj_number'];
449 $reverse_accOp->jrn=$old_receipt[
'jr_def_id'];
450 $reverse_accOp->update_receipt();
452 }
catch (\Exception
$e){
453 throw new \Exception(
'Echec extourne');
460 $Res=$this->
db->exec_sql(
" INSERT INTO quant_fin(
461 qf_bank, qf_other, qf_amount,jr_id,j_id)
462 SELECT qf_bank, qf_other, qf_amount*(-1),$1,$3
463 FROM quant_fin where jr_id=$2",
467 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR[ $sql ]"));
473 $rec->set_jr_id(
$seq);
474 $rec->insert($this->
jr_id);
479 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
484 $sql=
"delete from stock_goods where sg_id = any ( select sg_id
485 from stock_goods natural join jrnx where j_grpt=$1)";
486 $Res=$this->
db->exec_sql(
$sql,array($this->jr_grpt_id));
489 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
500 $this->
db->rollback();
513 $this->ledger_name=
_(
"Grand Livre");
517 $Res=$this->
db->exec_sql(
"select jrn_def_name from ".
518 " jrn_def where jrn_def_id=$1", array($this->
id));
525 $this->ledger_name=
$ret[
'jrn_def_name'];
526 return $ret[
'jrn_def_name'];
540 $pj_pref=
$prop[
"jrn_def_pj_pref"];
541 $padding=
$prop[
'jrn_def_pj_padding'];
543 return $pj_pref.str_pad(
$pj_seq,$padding??0,
'0',STR_PAD_LEFT);
564 $Res=$this->
db->get_row(
"select *
566 where jrn_def_id=$1", array($this->
id));
569 echo
'<DIV="redcontent"><H2 class="error">'._(
'Parametres journaux non trouves').
'</H2> </DIV>';
587 $ledger=
" and j_jrn_def = ".$this->id;
591 $sql=
'select j_montant as montant,j_debit as deb from jrnx where '
602 if (
$line[
'deb']==
't')
656 $sql=
"select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
657 " from jrn_def where ".
660 $r=$this->
db->exec_sql(
$sql, array($this->
id));
677 $sql=
"select jrn_def_class_deb ".
678 " from jrn_def where ".
681 $r=$this->
db->exec_sql(
$sql, array($this->
id));
706 return _(
"Aucun résultat");
710 $lPeriode=
new Periode($this->
db);
713 $lPeriode->p_id=$period;
717 $lPeriode->find_periode(
$e_date);
727 _(
"Attention : il vaut mieux utiliser les fiches que les postes comptables"));
730 $ret.=
"<tr><td>"._(
'Date').
" : </td><td>$e_date</td></tr>";
734 $ret.=
"<tr><td>"._(
'Libellé').
" </td><td>".
h(
$desc).
"</td></tr>";
736 $ret.=
_(
'Note').
'</td><td><pre>'.
h(
$p_array[
'jrn_note_input']).
'</pre>';
744 if (
$p_readonly ==
false)
$ret.=
"<tr><td>"._(
'PJ Num').
" </td><td>".
h($e_pj).$span.
"</td></tr>";
745 if (
$p_readonly ==
true )
$ret.=
"<tr><td>"._(
'PJ Num').
" </td><td>".
h($this->pj).$span.
"</td></tr>";
747 $ret.=
"<table class=\"result\">";
749 $ret.=
"<th>"._(
'Quick Code ou ');
750 $ret.=
_(
"Poste").
" </th>";
751 $ret.=
"<th style=\"text-align:left\"> "._(
"Libellé").
" </th>";
752 $ret.=
"<th style=\"text-align:right\">"._(
"Débit").
"</th>";
753 $ret.=
"<th style=\"text-align:right\">"._(
"Crédit").
"</th>";
758 $a_anc=
$anc->get_list();
761 $ret.=
'<th colspan="'.$x.
'" style="width:auto;text-align:center" >'.
_(
'Compt. Analytique').
'</th>';
770 $ret.=HtmlInput::hidden(
'period', $lPeriode->p_id);
771 $ret.=HtmlInput::hidden(
'e_pj', $e_pj);
772 $ret.=HtmlInput::hidden(
'e_pj_suggest', $e_pj_suggest);
773 $ret.=HtmlInput::hidden(
'jrn_note_input',
h(
$p_array[
'jrn_note_input']));
776 $ret.=HtmlInput::hidden(
'mt', $mt);
778 $ret.=HtmlInput::hidden(
'e_comm',
$desc);
780 $ret.=HtmlInput::hidden(
'p_jrn', $this->
id);
781 $ret.=HtmlInput::hidden(
'nb_item', $nb_item);
784 $ret.=HtmlInput::hidden(
'jrn_concerned', $jrn_concerned);
786 $ret.=dossier::hidden();
788 for (
$i=0;
$i<$nb_item;
$i++)
792 if (!isset(${
'qc_'.$i}))
794 if (!isset(${
'poste'.$i}))
796 if (!isset(${
'amount'.$i}))
799 $class=(
$i%2==0)?
' class="even" ':
' class="odd" ';
800 $ret.=
"<tr $class> ";
801 if (trim(${
'qc_'.$i})!=
"")
804 $oqc->get_by_qcode(${
'qc_'.$i},
false);
813 if (trim(${
'qc_'.$i})==
""&&trim(${
'poste'.$i})!=
"")
816 $strPoste=$oposte->id;
817 $ret.=
"<td>".h(${
"poste".$i}.
" - ".
818 $oposte->get_name()).HtmlInput::hidden(
'poste'.
$i,
823 if (trim(${
'qc_'.$i})==
""&&trim(${
'poste'.$i})==
"")
825 $ret.=
"<td>".h(${
"ld".$i}).HtmlInput::hidden(
'ld'.
$i, ${
'ld'.$i});
826 $ret.=(isset(${
"ck$i"}))?HtmlInput::hidden(
'ck'.
$i, ${
'ck'.$i}):
"";
828 if (isset(${
"ck$i"}))
830 $ret.=
"<td class=\"num\">".nbm(${
"amount".$i}).HtmlInput::hidden(
'amount'.
$i,
831 ${
'amount'.$i}).
"</td>".
td(
"");
832 $total_deb=bcadd($total_deb, ${
'amount'.$i});
836 $ret.=
td(
"").
"<td class=\"num\">".
nbm(${
"amount".$i}).HtmlInput::hidden(
'amount'.
$i,
837 ${
'amount'.$i}).
"</td>";
838 $total_cred=bcadd($total_cred, ${
"amount".$i});
850 $ret.=HtmlInput::hidden(
'op[]=',
$i);
852 $ret.=
'<td style="text-align:center">';
855 round(${
'amount'.$i}, 2));
866 $currency_code=
$http->extract(
"p_currency_code",
"number");
867 $currency_rate=
$http->extract(
"p_currency_rate",
"number");
869 $msg_currency= ($currency_code != 0 )?sprintf(
_(
"Totaux %s (%s)"),
$currency->get_code(),$currency_rate):
_(
"Totaux");
871 $ret.=
tr(
td(
'').
td($msg_currency).
td($total_deb,
'class="num"').
td($total_cred,
872 'class="num"'),
'class="highlight"');
874 if ( $currency_code != 0)
876 $currency_rate=
$http->extract(
"p_currency_rate",
"number");
881 td(bcdiv($total_deb,$currency_rate),
'class="num"').
882 td(bcdiv($total_cred,$currency_rate),
'class="num"'),
883 'class="highlight"');
888 $ret.=
'<input type="button" class="button" value="'._(
'verifie Imputation Analytique').
889 '" onClick="verify_ca(\'\');">';
897 $row=$this->
db->get_value(
"select jrn_deb_max_line from jrn_def where jrn_def_id=$1",
922 $add_js=
"update_receipt();";
926 $add_js.=
'get_last_date();';
928 $add_js.=
'update_row("quick_item");';
938 throw new Exception(
_(
'Pas de journal disponible'));
940 $wLedger->javascript=
"onChange='update_name();update_predef(\"ods\",\"t\",\"".$ac.
"\");$add_js'";
941 $label=
" Journal ".Icon_Action::infobulle(2);
950 echo
'<div id="predef_form">';
951 echo HtmlInput::hidden(
'p_jrn_predef', $this->
id);
953 $op->set_p_jrn($this->
id);
954 $op->set_jrn_type(
"ODS");
956 $url=http_build_query(
957 array(
'action'=>
'use_opd',
958 'p_jrn_predef'=>$this->
id,
960 'gDossier'=>dossier::id()));
961 echo
$op->form_get(
'do.php?'.
$url);
964 $str_op_template=ob_get_contents();
967 $ret.=
"<td>"._(
"Modèle d'opération").
"</td>";
968 $ret.=
"<td>".$str_op_template.
"</td>";
984 $l_user_per=
$g_user->get_periode();
994 $l_form_per=$period->input();
999 if (
$e->getCode()==1)
1001 echo
_(
"Aucune période ouverte");
1006 $f_periode=
td(
_(
"Période comptable").
" $label ").td($l_form_per);
1009 $wPJ=
new IText(
'e_pj');
1010 $wPJ->readonly=
false;
1021 $wPJ->setReadOnly(
true);
1022 $wPJ->value=$default_pj;
1025 $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
1029 $ret.=
'<td style="width:auto"> '._(
'Pièce').
' </td> ';
1037 $wDescription=
new IText(
'desc');
1039 $wDescription->size = (empty(
$desc))?60:strlen(
$desc)+5;
1040 $wDescription->size = ($wDescription->size<60)?60:$wDescription->size;
1041 $wDescription->value=(isset(
$desc))?
$desc:
'';
1042 $ret.=$wDescription->input();
1051 $ret.=
'<td> <pre id="jrn_note_td"></pre></td>';
1053 $currency_select = $this->
CurrencyInput(
"currency_code",
"p_currency_rate" ,
"p_currency_euro");
1054 $currency_select->selected=
$http->request(
'p_currency_code',
'string',0);
1056 $currency_input=
new INum(
"p_currency_rate");
1057 $currency_input->prec=8;
1058 $currency_input->id=
"p_currency_rate";
1059 $currency_input->value=
$http->request(
'p_currency_rate',
'string',1);
1060 $ret.=
tr(
td(
_(
"Devise")).
td($currency_select->input().
1061 $currency_input->change(
'CurrencyComputeMisc(\'p_currency_rate\',\'p_currency_euro\');')));
1071 $ret.=ob_get_contents();
1074 $ret.=HtmlInput::hidden(
'e_pj_suggest', $default_pj);
1081 $ret.=dossier::hidden();
1082 $ret.=HtmlInput::hidden(
'jrn_type', $this->
get_type());
1085 $ret.=
'<table id="quick_item" style="width:100%">';
1087 '<th style="text-align:left">Quickcode'.$info.
'</th>'.
1088 '<th style="text-align:left">'._(
'Poste').$info_poste.
'</th>'.
1089 '<th class="visible_gt800 visible_gt1155" style="text-align:left">'._(
'Libellé').
'</th>'.
1090 '<th style="text-align:left">'._(
'Montant').
'</th>'.
1091 '<th style="text-align:left">'._(
'Côté').
'</th>'.
1099 $quick_code->set_dblclick(
"fill_ipopcard(this);");
1111 $quick_code->javascript=sprintf(
' onchange="fill_data_onchange(\'%s\');" ',
1114 $quick_code->value=(isset(${
'qc_'.$i}))?${
'qc_'.$i}:
"";
1129 $poste->set_attribute(
'ipopup',
'ipop_account');
1130 $poste->set_attribute(
'label',
'ld'.
$i);
1131 $poste->set_attribute(
'account',
'poste'.
$i);
1132 $poste->set_attribute(
'dossier', Dossier::id());
1134 $poste->value=(isset(${
'poste'.$i}))?${
"poste".$i}:
''
1136 $poste->dbl_click_history();
1143 $label=$Poste->get_lib();
1147 $line_desc=
new IText();
1148 $line_desc->name=
'ld'.$i;
1149 $line_desc->size=30;
1150 $line_desc->value=(isset(${
"ld".$i}))?${
"ld".$i}:
1157 $amount->value=(isset(${
'amount'.$i}))?${
"amount".$i}:
''
1160 $amount->javascript=
'onChange="format_number(this);checkTotalDirect()"';
1164 $deb->selected=(isset(${
'ck'.$i}))?
true:
false;
1166 $deb->javascript=
'class="debit-credit" onChange="checkTotalDirect()"';
1167 $str_add_button=($add_card==
true)?$this->
add_card(
"-1",
1170 $ret.=
'<td>'.$quick_code->input().$quick_code->search().$str_add_button.
'</td>';
1171 $ret.=
'<td>'.$poste->input().
1173 'document.getElementById(\'poste'.$i.
'\').onblur=
function(){
'.
1174 'if (trim(this.
value) !=\
'\')
'.
1175 '{document.getElementById(\
'qc_'.
$i.
'\').value=
"";}}
'.
1178 $ret.='<
td class=
"visible_gt800 visible_gt1155">
'.$line_desc->input().'</
td>
';
1179 $ret.='<
td>
'.$amount->input().'</
td>
';
1180 $ret.='<
td>
'.$deb->input()
1181 .'<
span id=
"txt'.$deb->id.'"></
span>
'
1184 // If readonly == 1 then show CA
1187 if (isset($this->with_concerned)&&$this->with_concerned==true)
1189 $oRapt=new Acc_Reconciliation($this->db);
1190 $w=$oRapt->widget();
1191 $w->name='jrn_concerned
';
1192 $w->value=(isset($jrn_concerned))?$jrn_concerned:"";
1193 $ret.=sprintf(_("Réconciliation/rapprochements : %s"), $w->input());
1195 $ret.=create_script("$('".$wDate->id."').focus()");
1196 // for displaying Credit or Debit
1197 $ret.=create_script("(function(){activate_checkbox_side()})();");
1208 function is_closed($p_periode)
1210 $per=new Periode($this->db);
1211 $per->set_ledger($this->id);
1212 $per->set_periode($p_periode);
1213 $ret=$per->is_closed();
1227 function verify_operation($p_array)
1229 global $g_parameter;
1230 $http=new HttpInput();
1231 if (is_array($p_array)==false||empty($p_array))
1232 throw new Exception("Array empty");
1234 * Check needed value
1236 check_parameter($p_array, 'p_jrn,e_date
');
1238 extract($p_array, EXTR_SKIP);
1243 $http->set_array($p_array);
1244 /* Check currency : rate cannot be equal to 0 */
1245 $currency_rate=$http->extract("p_currency_rate","number");
1246 if ( $currency_rate <=0 ) {
1247 throw new Exception(_("Taux de conversion doit être supérieur à 0"),3);
1249 /* Check currency : Does the currency parameter exist */
1250 $currency_code=$http->extract("p_currency_code","number");
1251 $currency=new Acc_Currency($this->db,$currency_code);
1253 $this->check_currency_setting($currency_code);
1255 /* check if we can write into this ledger */
1256 if ($g_user->check_jrn($p_jrn)!='W
')
1257 throw new Exception(_('Accès interdit
'), 20);
1259 /* check for a double reload */
1260 if (isset($mt)&&$this->db->count_sql('select jr_mt
from jrn where jr_mt=$1
',
1262 throw new Exception(_('Double Encodage
'), 5);
1264 // Check the periode and the date
1265 if (isDate($e_date)==null)
1267 throw new Exception(_('Date invalide
'), 2);
1269 $periode=new Periode($this->db);
1270 /* find the periode if we have enabled the check_periode
1271 * or if period is not set
1273 if ($this->check_periode()==false||!isset($p_array['period
']))
1276 $periode->find_periode($e_date);
1277 } catch (Exception $e) {
1278 throw new Exception(_("Période inexistante"), 6, $e);
1283 $periode->p_id=$p_array['period
'];
1284 list ($min, $max)=$periode->get_date_limit();
1285 if (cmpDate($e_date, $min)<0||
1286 cmpDate($e_date, $max)>0)
1287 throw new Exception(_('Date et periode ne correspondent pas
'), 6);
1293 if ($this->is_closed($periode->p_id)==1)
1295 throw new Exception(_('Periode fermee
'), 6);
1297 /* check if we are using the strict mode */
1298 if ($this->check_strict()==true)
1300 /* if we use the strict mode, we get the date of the last
1302 $last_date=$this->get_last_date();
1303 if ($last_date!=null&&cmpDate($e_date, $last_date)<0)
1304 throw new Exception(
1306 _('Vous utilisez le mode strict la dernière operation est la date du %s
1307 vous ne pouvez pas encoder à une date antérieure
'),$last_date),
1311 for ($i=0; $i<$nb_item; $i++)
1315 // compatibily php 8.0 , if $amount is not a number then skip
1316 if (!isset(${'amount
'.$i}) || isNumber(${'amount
'.$i})==0) {
1320 // Check the balance
1321 $amount=round(${'amount
'.$i}, 2);
1322 $tot_deb+=(isset(${'ck
'.$i}))?$amount:0;
1323 $tot_cred+=(!isset(${'ck
'.$i}))?$amount:0;
1325 // Check if the card is permitted
1326 if (isset(${'qc_
'.$i})&&trim(${'qc_
'.$i})!="")
1328 $f=new Fiche($this->db);
1329 $f->get_by_qcode(${'qc_
'.$i});
1330 $f->quick_code=${'qc_
'.$i};
1332 if ($f->get_f_enable() == '0
')
1333 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée
"),${'qc_'.$i}), 50);
1334 if ($f->belong_ledger($p_jrn) < 1 )
1335 throw new Exception("La fiche quick_code =
".
1336 $f->quick_code." n'est pas accessible depuis ce journal, à configurer dans C0JRN", 4);
1337 if (noalyss_strlentrim(${'qc_
'.$i})!=0&&isNumber(${'amount
'.$i})==0)
1338 throw new Exception(_('Montant invalide
'), 3);
1340 $strPoste=$f->get_attribute(ATTR_DEF_ACCOUNT);
1342 throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable
"),
1345 $p=new Acc_Account_Ledger($this->db, $strPoste);
1346 if ($p->do_exist()==0)
1347 throw new Exception(_('Poste Inexistant pour la fiche ['.${'qc_'.$i}.']'),
1351 // Check if the account is permitted
1352 if (isset(${'poste'.$i})&&noalyss_strlentrim(${'poste'.$i})!=0)
1354 $p=new Acc_Account_Ledger($this->db, ${'poste'.$i});
1355 if ($p->belong_ledger($p_jrn)<0) {
1356 throw new Exception(sprintf (
1357 _("Le poste %s
n'est pas accessible dans ce journal, à configurer dans C0JRN",$p->id)),
1360 if (noalyss_strlentrim(${'poste
'.$i})!=0&&isNumber(${'amount
'.$i})==0)
1361 throw new Exception(_('Poste invalide [
'.${'poste
'.$i}.']
'),
1363 if ($p->do_exist()==0)
1364 throw new Exception(_('Poste Inexistant [
'.${'poste
'.$i}.']
'),
1366 $card_id=$p->find_card();
1367 if (!empty($card_id))
1369 $str_msg=sprintf(_(" Le poste %s appartient à fiche(s) dont : %s"),$p->id,count($card_id));
1370 $max=(count($card_id)>MAX_COMPTE_CARD)?MAX_COMPTE_CARD:count($card_id);
1371 for ($x=0; $x<$max; $x++)
1373 $card=new Fiche($this->db, $card_id[$x]['f_id
']);
1374 $str_msg.=HtmlInput::card_detail($card->get_attribute(ATTR_DEF_QUICKCODE),
1375 $card->get_attribute(ATTR_DEF_NAME),
1376 'style=
"color:red;display:inline;text-decoration:underline"');
1381 $account=new Acc_Account($this->db,${"poste".$i});
1382 if ( $account->get_parameter("pcm_direct_use") == "N") {
1383 throw new Exception(sprintf (_("Utilisation directe interdite du poste comptable %s"), ${"poste".$i}));
1387 $tot_deb=round($tot_deb, 4);
1388 $tot_cred=round($tot_cred, 4);
1389 if ($tot_deb!=$tot_cred)
1391 throw new Exception(_("Balance incorrecte ")." debit = $tot_deb credit=$tot_cred ",
1408 function compute_internal_code($p_grpt)
1412 $num=$this->db->get_next_seq('s_internal
');
1413 $atype=$this->get_propertie();
1414 $type=substr($atype['jrn_def_code
'], 0, 1);
1415 $internal_code=sprintf("%s%06X", $type, $num);
1416 $this->jr_internal=$internal_code;
1417 return $internal_code;
1428 function save($p_array=null)
1432 throw new Exception('
save cannot use a empty array
');
1434 global $g_parameter;
1436 $http=new HttpInput();
1437 extract($p_array, EXTR_SKIP);
1438 if ( !isset($p_array['jrn_note_input
'])) {$p_array['jrn_note_input
']='';}
1441 $msg=$this->verify($p_array);
1444 echo $this->display_warning($msg,
1445 _("Attention : il vaut mieux utiliser les fiches que les postes comptables "));
1449 $seq=$this->db->get_next_seq('s_grpt
');
1450 $internal=$this->compute_internal_code($seq);
1452 $group=$this->db->get_next_seq("s_oa_group");
1456 $oPeriode=new Periode($this->db);
1457 $check_periode=$this->check_periode();
1458 if ($check_periode==false||!isset($p_array['period
']))
1460 $oPeriode->find_periode($e_date);
1464 $oPeriode->p_id=$period;
1470 $http->set_array($p_array);
1471 $currency_code=$http->extract( "p_currency_code","number",0);
1472 $currency_rate=$http->extract( "p_currency_rate","number",1);
1473 $currency_rate_ref=new Acc_Currency($this->db, $currency_code);
1475 for ($i=0; $i<$nb_item; $i++)
1477 if (!isset(${'qc_
'.$i})&&!isset(${'poste
'.$i}))
1479 $acc_op=new Acc_Operation($this->db);
1481 // First we save the jrnx
1482 if (isset(${'qc_
'.$i}))
1484 $qc=new Fiche($this->db);
1485 $qc->get_by_qcode(${'qc_
'.$i}, false);
1486 $sposte=$qc->get_attribute(ATTR_DEF_ACCOUNT);
1487 /* if there are 2 accounts take following the deb or cred */
1488 if (strpos($sposte, ',
')!=0)
1490 $array=explode(",", $sposte);
1491 $poste=(isset(${'ck
'.$i}))?$array[0]:$array[1];
1497 throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable
"),
1500 $quick_code=${'qc_'.$i};
1504 $poste=${'poste'.$i};
1507 $acc_op->date=$e_date;
1508 // compute the periode is do not check it
1509 if ($check_periode==false)
1510 $acc_op->periode=$oPeriode->p_id;
1512 if (noalyss_strlentrim(${'ld'.$i})!=0)
1513 $acc_op->desc=${'ld'.$i};
1515 // Amount in default currency , usually EUR
1516 $acc_op->amount=round(bcdiv(${'amount'.$i},$currency_rate),2);
1518 $acc_op->poste=$poste;
1519 $acc_op->jrn=$this->id;
1520 $acc_op->type=(isset(${'ck'.$i}))?'d':'c';
1521 $acc_op->qcode=$quick_code;
1522 $j_id=$acc_op->insert_jrnx();
1525 $operation_currency=new Operation_currency_SQL($this->db);
1526 if (isNumber(${'amount'.$i}) == 0) {
1527 $operation_currency->oc_amount=0;
1529 $operation_currency->oc_amount=round(${'amount'.$i}, 2);
1531 $operation_currency->oc_vat_amount=0;
1532 $operation_currency->oc_price_unit=0;
1533 $operation_currency->j_id=$j_id;
1534 $operation_currency->insert();
1536 $tot_amount=bcadd($tot_amount,round($acc_op->amount, 2));
1538 if ( $acc_op->type == 'd') {
1539 $tot_deb=bcadd($tot_deb, $acc_op->amount);
1540 }elseif ( $acc_op->type == 'c') {
1541 $tot_cred=bcadd($tot_cred,$acc_op->amount);
1544 if ($g_parameter->MY_ANALYTIC!="nu
")
1546 if ($g_parameter->match_analytic( $poste)==TRUE)
1549 // for each item, insert into operation_analytique */
1550 $op=new Anc_Operation($this->db);
1551 $op->set_currency_rate($currency_rate);
1552 $op->oa_group=$group;
1554 $op->oa_date=$e_date;
1555 $op->oa_debit=($acc_op->type=='d' )?'t':'f';
1556 $op->oa_description=$desc;
1558 // send the amount in default currency to analytic
1560 $an_array['amount'.$i]=$acc_op->amount;
1561 $op->save_form_plan($an_array, $count, $j_id);
1565 }// loop for each item
1566 $acc_end=new Acc_Operation($this->db);
1567 // Check the balance
1568 if ( bcsub($tot_deb,$tot_cred,2) != 0 && $currency_code != 0)
1571 $diff=bcsub($tot_cred, $tot_deb);
1572 // store the difference in currency_rounded_delta
1573 $poste_cred = $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED;
1577 $poste=$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB;
1582 // insert difference of change
1583 $acc_change=new Acc_Operation($this->db);
1584 $acc_change->amount=abs($diff);
1585 $acc_change->grpt=$seq;
1586 $acc_change->poste=$poste;
1587 $acc_change->jrn=$this->id;
1588 $acc_change->type=$side;
1589 $acc_change->date=$e_date;
1590 $acc_change->desc=_("Différence de change
");
1592 $change_j_id=$acc_change->insert_jrnx();
1594 $tot_deb=bcadd($tot_deb,$diff);
1597 $acc_end->amount=$tot_deb;
1598 if ($check_periode==false)
1600 $acc_end->periode=$oPeriode->p_id;
1602 $acc_end->date=$e_date;
1603 $acc_end->desc=$desc;
1604 $acc_end->grpt=$seq;
1605 $acc_end->jrn=$this->id;
1607 $acc_end->jr_optype=$jr_optype;
1608 $acc_end->currency_id=$currency_code;
1609 $acc_end->currency_rate=$currency_rate;
1610 $acc_end->currency_rate_ref=$currency_rate_ref->get_rate();
1612 // @var $jr_id (int) JRN.JR_ID
1613 $jr_id=$acc_end->insert_jrn();
1615 $this->jr_id=$jr_id;
1617 throw new Exception(_('Balance incorrecte'));
1619 $this->pj=$acc_end->update_receipt();
1620 /* if e_suggest != e_pj then do not increment sequence */
1621 if ($this->pj == $e_pj_suggest &&noalyss_strlentrim($e_pj)!=0)
1623 $this->inc_seq_pj();
1628 $this->db->exec_sql("update jrn set jr_internal=$1
1629 where jr_grpt_id = $2
",array($internal,$seq));
1631 $this->jr_internal=$internal;
1632 // Save now the predef op
1633 //------------------------
1634 if (isset($opd_name)&&trim($opd_name)!="")
1636 $opd=new Pre_operation($this->db);
1637 $opd->set_od_direct('t');
1642 if (isset($this->with_concerned)&&$this->with_concerned==true)
1644 $orap=new acc_reconciliation($this->db);
1645 $orap->jr_id=$jr_id;
1647 $orap->insert($jrn_concerned);
1652 if (isset($_FILES["pj
"]))
1654 $acc_document=new Acc_Document($this->db, $jr_id);
1655 $acc_document->save_receipt();
1657 /*----------------------------------------------
1659 ----------------------------------------------*/
1660 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
1661 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
1662 $acc_operation_note->setNote($p_array['jrn_note_input']);
1663 $acc_operation_note->setOperation_id( $jr_id);
1664 $acc_operation_note->save();
1667 catch (Exception $e)
1670 $this->db->rollback();
1671 echo_warning(_('OPERATION ANNULEE voir log'));
1674 $this->db->commit();
1687 static function next_number($p_cn, $p_type)
1690 $Ret=$p_cn->count_sql("select *
from jrn_def where jrn_def_type=
'".$p_type."'");
1699 public function get_first($p_type, $p_access=3)
1702 $all=$g_user->get_ledger($p_type, $p_access,false);
1703 if (empty ($all)) return NULL;
1711 function update_paid($p_array)
1713 // reset all the paid flag because the checkbox is post only
1715 foreach ($p_array as $name=> $paid)
1717 list($ad)=sscanf($name, "set_jr_id%d
");
1721 $Res=$this->db->exec_sql($sql);
1723 // set a paid flag for the checked box
1724 foreach ($p_array as $name=> $paid)
1726 list ($id)=sscanf($name, "rd_paid%d
");
1731 $Res=$this->db->exec_sql($sql);
1735 function update_internal_code($p_internal)
1737 if (!isset($this->jr_grpt_id))
1738 throw new Exception(('ERREUR jr_grpt_id not set '.__FILE__.":
".__LINE__));
1739 $Res=$this->db->exec_sql("update jrn set jr_internal=$1 where
1740 jr_grpt_id = $2
",array($p_internal,$this->jr_grpt_id));
1749 function get_default_card($p_ledger_type, $p_side)
1752 $fiche_def_ref=new Fiche_Def_Ref($this->db);
1753 // ----- for FINANCIAL ----
1754 if ($p_ledger_type=='FIN')
1756 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
1757 $array=array_merge($array,
1758 $fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
1759 $array=array_merge($array,
1760 $fiche_def_ref->get_by_modele(FICHE_TYPE_FIN));
1761 $array=array_merge($array,
1762 $fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
1763 $array=array_merge($array,
1764 $fiche_def_ref->get_by_modele(FICHE_TYPE_EMPL));
1766 // --- for miscellaneous ----
1767 if ($p_ledger_type=='ODS')
1769 $result=$this->db->get_array('select fd_id from fiche_def');
1770 for ($i=0; $i<count($result); $i++)
1772 $array[$i]=$result[$i]['fd_id'];
1777 switch ($p_ledger_type)
1780 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
1783 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_SER);
1784 $array=array_merge($array,
1785 $fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAR));
1786 $array=array_merge($array,
1787 $fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAT));
1790 throw new Exception(_('get_default_card p_ledger_side is invalide ['.$p_ledger_type.']'));
1793 elseif ($p_side=='C')
1795 switch ($p_ledger_type)
1798 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_VENTE);
1801 $array=array_merge($array,
1802 $fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
1803 $array=array_merge($array,
1804 $fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
1807 throw new Exception(_('get_default_card p_ledger_side is invalide ['.$p_ledger_type.']'));
1813 $return = array_values($array);
1814 for ($i = 0;$i<count($array);$i++ )
1816 $return[$i]=$array[$i]['fd_id'];
1828 function get_all_fiche_def()
1830 $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred
".
1831 " from jrn_def where
".
1834 $r=$this->db->exec_sql($sql, array($this->id));
1836 $res=Database::fetch_all($r);
1841 foreach ($res as $item)
1843 if (noalyss_strlentrim($item['deb'])!=0)
1845 $card.=$comma.$item['deb'];
1848 if (strlen(noalyss_trim($item['cred']))!=0)
1850 $card.=$comma.$item['cred'];
1862 function check_strict()
1864 global $g_parameter;
1865 if ($g_parameter->MY_STRICT=='Y')
1867 if ($g_parameter->MY_STRICT=='N')
1869 throw new Exception("Valeur invalid
".__FILE__.':'.__LINE__);
1877 function check_periode()
1879 global $g_parameter;
1880 if ($g_parameter->MY_CHECK_PERIODE=='Y')
1882 if ($g_parameter->MY_CHECK_PERIODE=='N')
1884 throw new Exception("Valeur invalid
".__FILE__.':'.__LINE__);
1892 function check_currency_setting ($p_currency_code)
1894 global $g_parameter;
1895 if ( $p_currency_code == -1 )
1897 throw new Exception(_('Devise inconnue'), 3);
1899 /* -- check the accounting for error of exchange -*/
1900 if ($p_currency_code > 0 )
1902 $poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
1904 if ($poste->get_parameter("
id") == -1 )
1906 throw new Exception(
1907 sprintf(_("Dans COMPANY, vous
n'avez pas paramétré correctement ".
1908 " le compte de débit %s pour les erreurs de conversion"),
1909 $g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
1912 $poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
1913 if ($poste->get_parameter("id") == -1 )
1915 throw new Exception(
1916 sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement
".
1917 " le compte de crédit %s pour les erreurs de conversion
"),
1918 $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
1932 function check_currency($p_qcode_payment, $p_currency_id)
1934 $card=new Fiche($this->db);
1935 $card->get_by_qcode($p_qcode_payment);
1936 if ( $card->id == 0) throw new Exception (_("
Fiche invalide
"));
1938 $ledger = $card->get_bank_ledger();
1939 if ( $ledger != NULL )
1941 $ledger_currency_id=$ledger->get_currency()->get_id();
1942 // if sale and payment are not the same currency and the
1943 if ($ledger_currency_id != 0 && $p_currency_id != $ledger_currency_id )
1945 throw new Exception (_("Devise de la banque doit être identique à l
'opération"));
1952 function get_last_date()
1955 throw new Exception(__FILE__.":".__LINE__."Journal incorrect ");
1956 $sql="select to_char(max(jr_date),'DD.MM.YYYY
') from jrn where jr_def_id=$1";
1957 $date=$this->db->get_value($sql, array($this->id));
1967 function get_id($p_internal)
1970 $value=$this->db->get_value($sql, array($p_internal));
1983 function create_document($internal, $p_array)
1985 $id=$this->db->get_value('select
jr_id from jrn where jr_internal=$1
',
1990 $acc_document=new Acc_Document($this->db,$id);
1991 $acc_document->create_document($internal,$p_array);
1992 return h($acc_document->d_name.' (
'.$acc_document->d_filename.')
');
2000 public function check_payment($e_mp, $e_mp_qcode)
2002 /* Check if the "paid by" is empty, */
2005 /* the paid by is not empty then check if valid */
2006 $empl=new Fiche($this->db);
2007 $empl->get_by_qcode($e_mp_qcode);
2008 if ($empl->empty_attribute(ATTR_DEF_ACCOUNT)==true)
2010 throw new Exception(_("Le moyen de paiement choisi n'a pas de poste comptable
"),
2013 /* get the account and explode if necessary */
2014 $sposte=$empl->get_attribute(ATTR_DEF_ACCOUNT);
2015 // if 2 accounts, take only the debit one for customer
2016 if (strpos($sposte, ',')!=0)
2018 $array=explode(',', $sposte);
2019 $poste_val=$array[0];
2025 $poste=new Acc_Account_Ledger($this->db, $poste_val);
2026 if ($poste->load()==false)
2028 throw new Exception(sprintf(_("Pour la fiche %s le poste comptable [%s]
n'existe pas"),
2029 $empl->quick_code, $poste->id), 9);
2036 function inc_seq_pj()
2038 $sql="select nextval('s_jrn_pj
".$this->id."')";
2039 $this->db->exec_sql($sql);
2049 function get_last($p_limit)
2052 $filter_ledger=$g_user->get_ledger_sql('
ALL', 3);
2053 $filter_ledger=noalyss_str_replace('jrn_def_id', 'jr_def_id
', $filter_ledger);
2055 select jr_id,jr_pj_number,jr_date,to_char(jr_date,'DD.MM.YYYY
') as jr_date_fmt,jr_montant, jr_comment,jr_internal,jrn_def_code
2057 join jrn_def on (jrn_def_id=jr_def_id)
2058 where $filter_ledger
2059 order by jr_date desc , substring(jr_pj_number,'[0-9]+$
')::numeric desc limit $p_limit";
2060 $array=$this->db->get_array($sql);
2071 function search_group($p_what, $p_value)
2076 return $this->db->get_value('select jr_grpt_id
from jrn where jr_internal=$1
',
2086 function get_operation($p_from, $p_to)
2089 $jrn=($this->id==0)?'and
'.$g_user->get_ledger_sql():' and jr_def_id =
'.$this->id;
2090 $sql="select jr_id as id ,jr_internal as internal, ".
2091 "jr_pj_number as pj,jr_grpt_id,".
2092 " to_char(jr_date,'DDMMYY
') as date_fmt, ".
2093 " jr_comment as comment, jr_montant as montant ,".
2094 " jr_grpt_id,jr_def_id,jrn.currency_id,currency_rate,currency_rate_ref,cr_code_iso ".
2095 " from jrn join jrn_def on (jr_def_id=jrn_def_id) ".
2096 " left join currency on (currency.id=jrn.currency_id) ".
2098 " jr_date >= (select p_start from parm_periode where p_id = $1)
2099 and jr_date <= (select p_end from parm_periode where p_id = $2)".
2100 ' '.$jrn.' order by jr_date,substring(jr_pj_number,\
'[0-9]+$\')::numeric asc';
2101 $ret=$this->
db->get_array(
$sql, array($p_from, $p_to));
2114 $array=$this->
db->get_array(
"select tva_id,tva_label,tva_poste
2116 where tva_rate != 0.0000
2117 and exists (select qp_vat_code from quant_purchase
2120 and exists (select j_id
2121 from jrnx where j_jrn_def = $1))
2127 $array=$this->
db->get_array(
"select tva_id,tva_label,tva_poste
2129 where tva_rate != 0.0000
2130 and exists (select qs_vat_code from quant_sold
2131 where qs_vat_code=tva_id
2133 exists (select j_id from jrnx where j_jrn_def = $1))
2160 $array=$this->
db->get_array(
'select sum(qp_price) as price,sum(qp_vat) as vat '.
2161 ',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv'.
2162 ',sum(coalesce(qp_nd_tva_recup,0)+coalesce(qp_nd_tva,0)) as tva_nd'.
2163 ',sum(qp_vat_sided) as tva_np'.
2164 ' from quant_purchase join jrnx using(j_id)
2165 where j_grpt=$1 ', array($p_jr_id));
2170 $array=$this->
db->get_array(
'select sum(qs_price) as price,sum(qs_vat) as vat '.
2173 ',sum(qs_vat_sided) as tva_np'.
2174 ' from quant_sold join jrnx using(j_id)
2175 where j_grpt=$1 ', array($p_jr_id));
2196 $array=$this->
db->get_array(
'select coalesce(sum(qp_vat),0) as sum_vat,tva_id
2197 from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
2198 where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
2203 $array=$this->
db->get_array(
'select coalesce(sum(qs_vat),0) as sum_vat,tva_id
2204 from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
2205 where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
2244 $exercise=
$periode->get_exercice();
2247 $min_date=
$min->first_day();
2249 $periode_max=
new Periode($this->
db, $p_to);
2250 $max_date=$periode_max->first_day();
2256 $sql=
"select coalesce(sum(qp_price),0) as price".
2257 " ,coalesce(sum(qp_vat),0) as vat ".
2258 ',coalesce(sum(qp_dep_priv),0) as priv'.
2259 ',coalesce(sum(qp_vat_sided),0) as reversed'.
2260 ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd'.
2261 ',coalesce(sum(qp_vat_sided),0) as tva_np'.
2262 ' from quant_purchase join jrnx using(j_id) '.
2263 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
2264 ' and j_jrn_def = $3';
2266 array($min_date, $max_date, $this->
id));
2270 $array=$this->
db->get_array(
"select coalesce(sum(qp_vat),0) as sum_vat,tva_id
2271 from quant_purchase as p
2272 right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
2275 and j_date >= to_date($1,'DD.MM.YYYY')
2276 and j_date < to_date($2,'DD.MM.YYYY')
2279 array($min_date, $max_date, $this->
id));
2285 $sql=
"select coalesce(sum(qs_price),0) as price".
2286 " ,coalesce(sum(qs_vat),0) as vat ".
2289 ',coalesce(sum(qs_vat_sided),0) as reversed'.
2291 ' from quant_sold join jrnx using(j_id) '.
2292 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
2293 ' and j_jrn_def = $3';
2295 array($min_date, $max_date, $this->
id));
2298 $array=$this->
db->get_array(
"select coalesce(sum(qs_vat),0) as sum_vat,tva_id
2299 from quant_sold as p
2300 right join tva_rate on (qs_vat_code=tva_id)
2301 join jrnx using(j_id)
2304 j_date >= to_date($1,'DD.MM.YYYY')
2305 and j_date < to_date($2,'DD.MM.YYYY')
2308 array($min_date, $max_date, $this->
id));
2323 if ( $min_date <> $max_date)
2325 $cond=sprintf(
"j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ",
2326 $min_date,$max_date);
2328 $cond=sprintf(
"j_date = to_date('%s','DD.MM.YYYY') ",
2331 $saldo=$bank_card->get_bk_balance($cond);
2344 $exercise=
$periode->get_exercice();
2347 $min_date=
$min->first_day();
2349 $periode_max=
new Periode($this->
db, $p_to);
2350 $max_date=$periode_max->first_day();
2359 join jrnx using(j_id)
2360 join jrn_tax using (j_id)
2361 where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
2362 and j_jrn_def = $3";
2364 array($min_date, $max_date, $this->
id));
2366 return array(
'other_tax_amount',
$amount);
2375 join jrnx using(j_id)
2376 join jrn_tax using (j_id)
2377 where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
2378 and j_jrn_def = $3";
2380 array($min_date, $max_date, $this->
id));
2382 return array(
'other_tax_amount',
$amount);
2385 return array(
'other_tax_amount',0);
2397 echo Acc_Reconciliation::$javascript;
2399 $cn=Dossier::connect();
2401 $_SESSION[SESSION_KEY.
'g_pass']=
'phpcompta';
2405 $a->with_concerned=
true;
2407 echo
'<FORM method="post">';
2408 echo
$a->select_ledger()->input();
2409 echo HtmlInput::submit(
'go',
'Test it');
2414 echo
'<form method="post">';
2415 echo
$a->show_form();
2416 echo HtmlInput::submit(
'post_id',
'Try me');
2421 echo dossier::hidden();
2422 echo
'<input type="hidden" value="'.$id.
'" name="p_jrn">';
2426 if (
$op->count()!=0)
2428 echo HtmlInput::submit(
'use_opd',
2429 'Utilisez une opération prédéfinie',
2431 echo
$op->show_button();
2437 if (isset(
$_POST[
'post_id']))
2440 echo
'<form method="post">';
2442 echo HtmlInput::button(
'add',
'Ajout d\'une ligne',
2443 'onClick="quick_writing_add_row()"');
2444 echo HtmlInput::submit(
'save_it',
_(
"Sauver"));
2448 if (isset(
$_POST[
'save_it']))
2457 catch (Exception
$e)
2460 echo
'<form method="post">';
2463 echo HtmlInput::submit(
'post_id',
'Try me');
2470 if (isset(
$_GET[
'use_opd']))
2472 $op=
new Pre_op_advanced(
$cn);
2478 echo
'<FORM method="post">';
2481 echo HtmlInput::submit(
'post_id',
'Use predefined operation');
2488 if ($pCase==
'search')
2491 $cn=Dossier::connect();
2494 $_SESSION[SESSION_KEY.
'g_pass']=
'phpcompta';
2495 echo
$ledger->search_form(
'ALL');
2501 if ($pCase==
'reverse')
2503 $cn=Dossier::connect();
2508 $jrn_def_id=
$cn->get_value(
'select jr_def_id from jrn where jr_internal=$1',
2511 $ledger->jr_id=
$cn->get_value(
'select jr_id from jrn where jr_internal=$1',
2514 echo
"Ouvrez le fichier ".__FILE__.
" à la ligne ".__LINE__.
" pour changer jr_internal et vérifier le résultat de l'extourne";
2516 $ledger->reverse(
'01.07.2010');
2518 catch (Exception
$e)
2534 array(
'cat'=>
'VEN',
'name'=>
_(
"Journaux de vente")),
2535 array(
'cat'=>
'ACH',
'name'=>
_(
"Journaux d'achat")),
2536 array(
'cat'=>
'FIN',
'name'=>
_(
"Journaux Financier")),
2537 array(
'cat'=>
'ODS',
'name'=>
_(
"Journaux d'Opérations diverses"))
2550 switch ($p_jrn_type)
2553 $tiers=$this->
db->get_value(
'select max(qs_client) from quant_sold join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1',
2557 $tiers=$this->
db->get_value(
'select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn on (jr_grpt_id=j_grpt) where jrn.jr_id=$1',
2562 $tiers=$this->
db->get_value(
'select qf_other from quant_fin where jr_id=$1',
2566 if ($this->
db->count()==0)
2578 if ($p_jrn_type==
'ODS')
2584 $name=$this->
db->get_value(
'select ad_value from fiche_detail where ad_id=1 and f_id=$1',
2586 $first_name=$this->
db->get_value(
'select ad_value from fiche_detail where ad_id=32 and f_id=$1',
2588 return $name.
' '.$first_name;
2598 $base_url=
"?".dossier::get().
"&ac=".
$_REQUEST[
'ac'];
2601 $r.=
_(
'Cherche').
" ".HtmlInput::filter_table(
"cfgledger_table_id",
"0",
2603 $r.=
'<TABLE id="cfgledger_table_id" class="vert_mtitle">';
2604 $r.=
'<TR><TD class="first"><A HREF="'.$base_url.
'&sa=add">'.
_(
'Ajout journal').
' </A></TD></TR>';
2605 $ret=$this->
db->exec_sql(
"select distinct jrn_def_id,jrn_def_name,
2606 jrn_def_class_deb,jrn_def_class_cred,jrn_def_type
2607 from jrn_def order by jrn_def_name");
2614 $url=$base_url.
"&sa=detail&p_jrn=".$l_line[
'jrn_def_id'];
2615 $r.=sprintf(
'<TR ledger_type="%s"><TD><A HREF="%s">%s</A></TD></TR>', $l_line[
'jrn_def_type'],
$url,
2616 h($l_line[
'jrn_def_name']).
' ('.$l_line[
'jrn_def_type'].
')');
2628 if ($this->load()==
false)
2630 throw new Exception(
_(
"Journal n'existe pas"), -1);
2634 $code=$this->jrn_def_code;
2638 $wSearch->set_attribute(
'ipopup',
'ipop_account');
2639 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
2640 $wSearch->set_attribute(
'no_overwrite',
'1');
2641 $wSearch->set_attribute(
'noquery',
'1');
2643 $wSearch->name=
"p_jrn_class_deb";
2645 $wSearch->value=$this->jrn_def_class_deb;
2648 $wPjPref=
new IText();
2649 $wPjPref->name=
'jrn_def_pj_pref';
2651 $pj_pref=$wPjPref->input();
2655 $wPjSeq->name=
'jrn_def_pj_seq';
2660 $hidden=HtmlInput::hidden(
'p_jrn', $this->
id);
2661 $hidden.=HtmlInput::hidden(
'sa',
'detail');
2663 $hidden.=HtmlInput::hidden(
'p_jrn_deb_max_line', 10);
2664 $hidden.=HtmlInput::hidden(
'p_ech_lib',
'echeance');
2667 $min_row=
new INum(
"min_row", $this->jrn_deb_max_line);
2671 $description->style=
'class="itextarea" style="margin:0px;"';
2680 $num_op=
new ICheckBox(
'numb_operation');
2681 if ($this->jrn_def_num_op==1)
2682 $num_op->selected=
true;
2687 $f_id=$this->jrn_def_bank;
2691 $qcode_bank=$fBank->get_quick_code();
2697 $actif=
new ISelect(
"jrn_enable");
2699 [
"label"=>
_(
"Activé"),
"value"=>1],
2700 [
"label"=>
_(
"Désactivé"),
"value"=>0]
2707 $negative=
new InputSwitch(
'negative_amount',$this->jrn_def_negative_amount);
2708 $negative_warning=
new IText(
"negative_warning",
_($this->jrn_def_negative_warning));
2709 $negative_warning->size=55;
2712 $quantity=
new InputSwitch(
'p_jrn_quantity',$this->jrn_def_quantity);
2715 $padding = new \INum (
'p_jrn_padding',$this->jrn_def_pj_padding);
2716 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
2727 $default_currency->value=$this->
db->make_array(
"select id,cr_code_iso from public.currency order by 1 ");
2729 $nb_operation=$this->
db->get_value(
"select count(*) from jrn where jr_def_id=$1",[$this->
id]);
2761 $p_jrn_deb_max_line=
$http->extract(
'p_jrn_deb_max_line');
2762 $p_jrn_name=
$http->extract(
'p_jrn_name');
2763 $p_jrn_type=
$http->extract(
'p_jrn_type');
2764 $p_jrn_quantity=
$http->extract(
'p_jrn_quantity',
'number',0);
2769 throw new Exception(
"Id invalide");
2770 if (
isNumber($p_jrn_deb_max_line)==0)
2771 throw new Exception(
_(
"Nombre de ligne incorrect"));
2772 if (trim($p_jrn_name)==
"")
2773 throw new Exception(
"Nom de journal invalide");
2774 if ($this->
db->get_value(
"select count(*) from jrn_def where jrn_def_name=$1 and jrn_Def_id<>$2",
2775 array($p_jrn_name,
$p_jrn))>0)
2776 throw new Exception(
_(
"Un journal avec ce nom existe déjà"));
2777 if ($p_jrn_type==
'FIN')
2779 $http=new \HttpInput();
2781 $bank=
$http->post(
"bank");
2782 $result=
$a->get_by_qcode(trim(strtoupper($bank)),
false);
2784 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
2786 if ($p_jrn_type==
"-1")
2788 throw new Exception(
_(
'Choix du type de journal est obligatoire'));
2791 if ( isset(
$array[
'negative_warning']) &&
2792 isset(
$array[
'negative_amount']) &&
2793 $array[
'negative_amount'] == 1
2794 && trim(
$array[
'negative_warning'])==
"") {
2796 throw new Exception(
_(
"Avertissement ne peut être vide"));
2798 if ( isset(
$array[
'negative_amount']) &&
2799 $array[
'negative_amount'] <> 0 &&
2800 $array[
'negative_amount'] <> 1 )
2802 throw new Exception(
_(
"Valeur invalide {$array['negative_amount']}"));
2805 catch (Exception
$e)
2838 $this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity===
null)?1:
$this->jrn_def_quantity;
2848 $p_jrn_deb_max_line=
$http->extract(
"p_jrn_deb_max_line",
"number",-1);
2849 $min_row=
$http->extract(
"min_row");
2851 $this->jrn_def_id=
$http->extract(
'p_jrn');
2853 $this->jrn_def_ech_lib=
$http->extract(
'p_ech_lib');
2854 $this->jrn_def_max_line_deb=($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
2855 $this->jrn_def_type=
$http->extract(
'p_jrn_type');
2856 $this->jrn_def_pj_pref=
$http->extract(
'jrn_def_pj_pref');
2857 $this->jrn_deb_max_line=($min_row<1)?1:$min_row;
2858 $this->jrn_def_description=
$http->extract(
'p_description');
2859 $this->jrn_enable=
$http->extract(
'jrn_enable');
2860 $this->currency_id=0;
2861 $this->jrn_def_negative_amount=
$http->extract(
'negative_amount',
'string',0);
2862 $this->jrn_def_negative_warning=
$http->extract(
"negative_warning",
'string',
2863 _(
"Attention, ce journal doit utiliser des montants négatifs"));
2864 $this->jrn_def_quantity=
$http->extract(
'p_jrn_quantity',
'string',1);
2865 $jrn_def_pj_seq=
$http->extract(
"jrn_def_pj_seq");
2866 $this->jrn_def_pj_padding=
$http->extract(
'p_jrn_padding',
'number');
2867 switch ($this->jrn_def_type)
2870 $ACH_FICHECRED=
$http->extract(
'ACH_FICHECRED',
'array',array());
2871 $ACH_FICHEDEB=
$http->extract(
'ACH_FICHEDEB',
'array',array());
2872 $this->jrn_def_fiche_cred=(!empty($ACH_FICHECRED))?join(
',',$ACH_FICHECRED):
'';
2873 $this->jrn_def_fiche_deb=(!empty($ACH_FICHEDEB))?join(
',',$ACH_FICHEDEB):
"";
2876 $VEN_FICHECRED=
$http->extract(
'VEN_FICHECRED',
'array',array());
2877 $VEN_FICHEDEB=
$http->extract(
'VEN_FICHEDEB',
'array',array());
2878 $this->jrn_def_fiche_cred=(!empty($VEN_FICHECRED))?join(
',',$VEN_FICHECRED):
'';
2879 $this->jrn_def_fiche_deb=(!empty($VEN_FICHEDEB))?join(
',',$VEN_FICHEDEB):
"";
2883 $this->jrn_def_class_deb=
$http->extract(
'p_jrn_class_deb',
'string');
2884 $ODS_FICHEDEB=
$http->extract(
'ODS_FICHEDEB',
'array',array());
2885 $this->jrn_def_fiche_deb=(!empty($ODS_FICHEDEB))?join(
',',$ODS_FICHEDEB):
''; ;
2886 $this->jrn_def_fiche_cred=
null;
2891 $result=
$a->get_by_qcode(trim(strtoupper(
$http->extract(
'bank'))),
false);
2893 $this->jrn_def_bank=$bank;
2894 $FIN_FICHEDEB=
$http->extract(
'FIN_FICHEDEB',
'array',array());
2895 $this->jrn_def_fiche_deb=(!empty($FIN_FICHEDEB))?join(
',',$FIN_FICHEDEB):
"";
2897 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
2898 $this->jrn_def_num_op=
$http->extract(
'numb_operation',
'string',0);
2900 $nb_operation = $this->
db->get_value(
"select count(*) from jrn where jr_def_id=$1",
2901 [$this->jrn_def_id]);
2906 $this->currency_id=
$http->extract(
"defaultCurrency");
2908 $this->currency_id=$this->
db->get_value(
"select currency_id from jrn_def where jrn_def_id=$1",
2909 [$this->jrn_def_id]);
2916 if ($jrn_def_pj_seq!=0)
2918 $Res=$this->
db->alter_seq(
"s_jrn_pj".$this->jrn_def_id, $jrn_def_pj_seq);
2932 $r.=
'<div id="payment"> ';
2933 $r.=
'<h2 class="h-section"> '._(
'opération de paiement').
' </h2>';
2934 $r.=
'<p class="text-muted">';
2935 $r.=
_(
"Opération de paiement crée en plus de cette opération, ne concerne pas la facturation électronique");
2938 $mp->set_parameter(
'ledger_source', $this->
id);
2939 $r.=$mp->select($p_selected,$p_amount,
$p_date,$p_comm);
2951 $retry=
$http->post(
"sa",
"string",
"");
2953 $default_type=
$http->post(
"p_jrn_type",
"string", -1);
2954 $previous_jrn_def_pj_pref=
$http->post(
"jrn_def_pj_pref",
"string",
"");
2955 $previous_p_description=
$http->post(
"p_description",
"string",
"");
2956 $previous_p_jrn_name=
$http->post(
'p_jrn_name',
"string",
'');
2957 $previous_p_jrn_type=
$http->post(
"p_jrn_type",
"string",
"");
2960 $f_add_button->label=
_(
'Créer une nouvelle fiche');
2961 $f_add_button->tabindex=-1;
2962 $f_add_button->set_attribute(
'jrn', -1);
2963 $f_add_button->javascript=
" select_card_type({type_cat:4,elementId:'bank',p_jrn:-1});";
2969 $str_add_button=$f_add_button->input();
2973 $wSearch->set_attribute(
'ipopup',
'ipop_account');
2974 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
2975 $wSearch->set_attribute(
'no_overwrite',
'1');
2976 $wSearch->set_attribute(
'noquery',
'1');
2978 $wSearch->name=
"p_jrn_class_deb";
2997 $hidden=HtmlInput::hidden(
'p_jrn', -1);
2998 $hidden.=HtmlInput::hidden(
'p_action',
'jrn');
2999 $hidden.=HtmlInput::hidden(
'sa',
'add');
3001 $hidden.=HtmlInput::hidden(
'p_jrn_deb_max_line', 10);
3002 $hidden.=HtmlInput::hidden(
'p_ech_lib',
'echeance');
3005 $name=$previous_p_jrn_name;
3008 $a_jrn=$this->
db->make_array(
"select '-1',' -- ".
_(
"choix du type de journal").
" -- ' union select jrn_type_id,jrn_desc from jrn_type");
3009 $wType->selected=
'-1';
3010 $wType->value=$a_jrn;
3011 $wType->name=
"p_jrn_type";
3012 $wType->id=
"p_jrn_type_select_id";
3013 $wType->javascript=
' onchange="show_ledger_div()"';
3014 $wType->selected=$default_type;
3015 $type=$wType->input();
3016 $rcred=$rdeb=array();
3017 $wPjPref=
new IText();
3018 $wPjPref->name=
'jrn_def_pj_pref';
3019 $wPjPref->value=$previous_jrn_def_pj_pref;
3020 $pj_pref=$wPjPref->input();
3025 $description->style=
'class="itextarea" style="margin:0px;"';
3031 $num_op=
new ICheckBox(
'numb_operation');
3032 echo dossier::hidden();
3033 echo HtmlInput::hidden(
'ac',
$http->request(
'ac'));
3043 $negative_warning=
new IText(
'negative_warning',
_(
"Attention, ce journal doit utiliser des montants négatifs"));
3044 $negative_warning->size=
"55";
3047 $padding = new \INum (
'p_jrn_padding',5);
3048 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
3092 extract(
$array, EXTR_SKIP);
3093 $this->jrn_def_id=-1;
3095 $this->jrn_def_ech_lib=$p_ech_lib;
3096 $this->jrn_def_max_line_deb=$p_jrn_deb_max_line;
3097 $this->jrn_def_type=$p_jrn_type;
3099 $this->jrn_deb_max_line=$min_row;
3100 $this->jrn_def_code=trim(substr($this->jrn_def_type, 0, 1));
3101 $this->jrn_def_code.=str_pad(
3104 $this->jrn_def_code=strtoupper($this->jrn_def_code);
3105 $this->jrn_def_description=$p_description;
3106 $this->currency_id=0;
3107 $this->jrn_def_negative_amount=$negative_amount;
3108 $this->jrn_def_negative_warning=$negative_warning;
3109 $this->jrn_enable=1;
3110 $this->jrn_def_pj_padding=$p_jrn_padding;
3111 switch ($this->jrn_def_type)
3114 $this->jrn_def_fiche_cred=(isset($ACH_FICHECRED))?join(
',',$ACH_FICHECRED):
'';
3115 $this->jrn_def_fiche_deb=(isset($ACH_FICHEDEB))?join(
',',$ACH_FICHEDEB):
"";
3118 $this->jrn_def_fiche_cred=(isset($VEN_FICHECRED))?join(
',',$VEN_FICHECRED):
'';
3119 $this->jrn_def_fiche_deb=(isset($VEN_FICHEDEB))?join(
',',$VEN_FICHEDEB):
"";
3123 $this->jrn_def_class_deb=$p_jrn_class_deb;
3124 $this->jrn_def_fiche_deb=(isset($ODS_FICHEDEB))?join(
',',$ODS_FICHEDEB):
''; ;
3125 $this->jrn_def_fiche_cred=
null;
3129 $result=
$a->get_by_qcode(trim(strtoupper($bank)),
false);
3131 $this->jrn_def_bank=$bank_id;
3132 $this->jrn_def_fiche_deb=(isset($FIN_FICHEDEB))?join(
',',$FIN_FICHEDEB):
"";
3134 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
3135 $this->jrn_def_num_op=(isset($numb_operation))?1:0;
3136 $this->currency_id=$defaultCurrency;
3139 $this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity==
null)?1:
$this->jrn_def_quantity;
3152 if ($this->
db->get_value(
"select count(jr_id) from jrn where jr_def_id=$1",
3153 array($this->jrn_def_id))>0)
3154 throw new Exception(
_(
"Impossible d'effacer un journal qui contient des opérations"));
3157 catch (Exception
$e)
3178 switch ($p_ledger_type)
3187 throw new Exception(
'Ledger_type invalid : '.$p_ledger_type);
3189 if ( ! in_array($sql_op ,array(
'>',
'<',
'=',
'>=',
'<='))) {
3190 throw new \Exception (
"AC3162 : invalid \$sql_op = [$sql_op]");
3193 $sql=
"select jr_id, jr_internal, jr_date, jr_comment,jr_pj_number,jr_montant,jr_ech
3195 join jrn_def on (jrn_def_id=jr_def_id)
3198 and jr_ech $sql_op to_date($1,'DD.MM.YYYY')
3199 and coalesce (jr_rapt,'xx') <> 'paid'
3217 function get_rowSimple($p_from, $p_to, $pa_ledger=[],$trunc=0,$p_limit=-1,$p_offset=-1)
3219 if ( empty($pa_ledger) ) {
3223 if ( $pa_ledger == [0] ) {
3228 $alh_generic->get_rowSimple($trunc,$p_limit,$p_offset);
3229 $data=$alh_generic->get_data();
3282 if (!
$g_user->can_read_action($p_ag_id))
3283 die(
_(
'Action non accessible'));
3287 $tiers_id=$this->
db->get_value(
'select f_id_dest from action_gestion where ag_id=$1',
3289 if ($this->
db->size()!=0)
3290 $qcode=$this->
db->get_value(
'select j_qcode from vw_poste_qcode where f_id=$1',
3295 $comment=$this->
db->get_value(
'select ag_title from action_gestion where ag_id=$1',
3298 $array[
'e_comm']=$comment;
3301 $a_item=$this->
db->get_array(
'select f_id,ad_text,ad_pu,ad_quant,ad_tva_id,ad_tva_amount,j_qcode
3304 left join vw_poste_qcode using(f_id)
3306 ag_id=$1', array($p_ag_id));
3308 $array[
'nb_item']=($this->
nb>count($a_item))?$this->
nb:count($a_item);
3309 for (
$i=0;
$i<count($a_item);
$i++)
3311 $array[
'e_march'.$i]=$a_item[
$i][
'j_qcode'];
3312 $array[
'e_march'.$i.
'_label']=$a_item[
$i][
'ad_text'];
3313 $array[
'e_march'.$i.
'_price']=$a_item[
$i][
'ad_pu'];
3314 $array[
'e_march'.$i.
'_tva_id']=$a_item[
$i][
'ad_tva_id'];
3315 $array[
'e_march'.$i.
'_tva_amount']=$a_item[
$i][
'ad_tva_amount'];
3316 $array[
'e_quant'.$i]=$a_item[
$i][
'ad_quant'];
3318 if ( $copy_description == 1) {
3319 $acomment=$this->
db->get_array(
"SELECT agc_id, ag_id, to_char(agc_date,'DD.MM.YYYY HH24:MI') as str_agc_date, agc_comment, agc_comment_raw,tech_user
3320 FROM action_gestion_comment where ag_id=$1 order by agc_id", array($p_ag_id)
3322 if (count ($acomment) > 0)
3323 $array[
'jrn_note_input']=$acomment[0][
'agc_comment'];
3335 $lib=$this->
db->get_value(
'select pcm_lib from tmp_pcmn where pcm_val=$1',
3352 $r=(
$p_readonly==
false)?
'<div id="repo_div_id" style="height:185px;height:10rem;">':
'<div id="repo_div_id" >';
3356 $sel=HtmlInput::select_stock($this->
db,
'repo',
'W');
3359 $sel->selected=$p_repo;
3360 $r.=
"<p class=\"decale\">"._(
'Dans le dépôt').
" : ";
3365 $r.=
'<span class="notice">'.
'Stock non utilisé'.
'</span>';
3379 $button=HtmlInput::button_anchor(
_(
"Nouvelle opération"),
3380 'do.php?'.
$url,
"",
"",
"button");
3381 return '<p>'.$button.
'</p>';
3390 echo
'<FORM METHOD="POST">';
3391 echo HtmlInput::post_to_hidden(
3392 array(
"gDossier",
"ac",
"p_jrn",
"e_client",
"nb_item",
"desc",
"e_comm")
3394 echo HtmlInput::hidden(
"correct",
"copy");
3397 $nb=
$http->post(
"nb_item",
"number", 0);
3398 echo HtmlInput::post_to_hidden([
'p_currency_rate',
'p_currency_code']);
3399 echo HtmlInput::post_to_hidden([
'other_tax',
'other_tax_amount']);
3402 echo HtmlInput::post_to_hidden(
3405 "e_march".
$i.
"_price",
3406 "e_march".$i.
"_quant",
3407 "e_march".$i.
"_label",
3408 "e_march".$i.
"_tva_id",
3409 "e_march".$i.
"_tva_amount",
3418 echo HtmlInput::submit(
"copy_operation",
_(
"Opération identique"),p_class:
"button");
3430 $js_script=
"this.filter='{$p_filter}';this.elementId='{$p_id_update}';this.jrn=\$('p_jrn').value; select_card_type(this);";
3432 return $str_add_button;
3439 return $this->
db->get_value(
"select jrn_enable from jrn_def where jrn_def_id=$1",[$this->
id]);
3454 $this->jrn_def_quantity=$p_value;
3465 if ( $p_jrn_type ==
'ACH')
3467 $sql=
"select count(*) from jrnx join quant_purchase using (j_id) where j_grpt=$1";
3468 }
elseif ($p_jrn_type==
'VEN')
3470 $sql=
"select count(*) from jrnx join quant_sold using (j_id) where j_grpt=$1";
3471 }
elseif ($p_jrn_type==
'FIN')
3473 $sql=
"select count(*) from jrn join quant_fin using (jr_id) where jr_grpt_id=$1";
3475 }
elseif ($p_jrn_type==
'ODS')
return 0;
3478 throw new Exception(
_(
'Journal incorrect'),1000);
3483 if (
$count > 0)
return TRUE;
3503 $select->javascript=sprintf(
'onchange="LedgerCurrencyUpdateMisc(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
3504 '$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
3505 Dossier::id(),
$select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
3510 $select->javascript=sprintf(
'onchange="LedgerCurrencyUpdate(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
3511 '$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
3512 Dossier::id(),
$select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
3516 throw new Exception(
_(
"Journal type non déterminé"));
3527 if ( $cr->get_id() < 0 ) {
3528 throw new Exception(
"ACL.3214".
_(
"Taux invalide"));
3540 if ($this->
id == 0) {
3541 throw new Exception(
_(
"Journal invalide"), 1);
3544 if ( $p_amount > 0 &&
$ledger->getp(
"jrn_def_negative_amount")==1){
3545 return _(
$ledger->getp(
"jrn_def_negative_warning"));
3551 require NOALYSS_TEMPLATE.
"/acc_ledger-input_extra_info.php";
3561 if ($this->jr_id == 0 || empty ($s_related_action)) {
return false; }
3565 $acc_operation->insert_related_action($s_related_action);
3581 $amount->value=
$http->request(
"other_tax_amount",
"number",0);
3583 $amount->javascript=
'onchange="format_number(this,2);refresh_ledger();"';
3585 $row=$this->
cn->get_row(
"select ac_id,ac_label,ac_rate from acc_other_tax where $1 = any (ajrn_def_id)",
3590onchange=
'if (! this.checked) { $("other_tax_amount").value=0;}compute_all_ledger();'
3601 $out.=
"<h4>"._(
"Total opération").
3602 "<span class=\"mx-4\" id='total_operation_other_tax'>".
3614 $row=$this->
cn->get_row(
"select ac_id,ac_label,ac_rate from acc_other_tax where ac_id=$1",
3615 [$p_additional_tax]);
3618 $p_amount=
h($p_amount);
3620<div
id=
"additional_tax">
3635 $cnt=$this->
db->get_value(
'select count(*)
3637 where array_position(ajrn_def_id,$1) is not null',[$this->
id]);
3638 if (
$cnt == 0 )
return false;
3652 if (empty(
$p_array[
'e_pj']))
return true;
3653 if (empty(
$p_array[
'e_pj_suggest']))
return true;
3668 return span (
_(
"Attention ! Numéro de Pièce non automatique mais forcée"),
'class="warning"');
3678 if ( $this->
id==0) {
3679 throw new \Exception (
"ACL3674: invalid ledger",3674);
3684 $supplemental_doc=
new IFile(
'document_supplemental[]');
3685 $supplemental_doc->setAlertOnSize(
true);
3686 $supplemental_doc->set_multiple(
true);
3688 $r.=
_(
"Ajoutez des documents additionnels");
3689 $r.=$supplemental_doc->input();
3700 if (! isset ($_FILES[
'document_supplemental']) || count($_FILES[
'document_supplemental'][
'name'])==0) {
3703 $nb=count($_FILES[
'document_supplemental'][
"name"]);
3705 if ( $this->
db->status() !== PGSQL_TRANSACTION_INTRANS ) {
3711 $file= tempnam($_ENV[
"TMP"],
"sup_file");
3712 if ( move_uploaded_file($_FILES[
'document_supplemental'][
'tmp_name'][
$i],
$file))
3714 if ( ($oid=$this->
db->lo_import(
$file)) !=
false )
3718 $jrn_sup->js_lob=$oid;
3719 $jrn_sup->js_mimetype=$_FILES[
'document_supplemental'][
'type'][
$i];
3720 $jrn_sup->js_filename=$_FILES[
'document_supplemental'][
'name'][
$i];
3725 if (
$a == 1) { $this->
db->commit(); }
noalyss_bcsub($p_first, $p_second, $p_decimal=4)
h2($p_string, $p_class="", $raw="")
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
noalyss_explode($separator, $string)
to avoid deprecated in PHP8.1 : explode cannot use a null
span($p_string, $p_extra='')
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
html_page_start($p_theme="", $p_script="", $p_script2="")
Default page header for each page.
tr($p_string, $p_extra='')
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
nb($p_number)
format the number for the CSV export
td($p_string='', $p_extra='')
surround the string with td
nbm($p_number, $p_dec=2)
format the number with a sep.
alert($p_msg, $buffer=false)
alert in javascript
global $g_user
if no group available , then stop
for($i=0; $i< $nb_vatex_code; $i++)($i % 2==0) ? " odd " $cnt
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
if(trim($query)==''|| $filter=='') $search
if(isset( $_REQUEST[ 'show'])) if(isset($_REQUEST['del'])) $ac
if(! empty( $error)) for($i=0;$i< count($error);$i++)( $last !=$error[$i]) $last
_("actif, passif,charge,...")
$class
Display the Plugin and for each profile were it is installed or not.
Manage the account from the table jrn, jrnx or tmp_pcmn.
Manage the account from the table 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
manage the list of operation when we need several ledger with a different type or from Misceleaneous ...
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
use_quant_table($p_grpt_id, $p_jrn_type)
Check if the operation is used in the table quant*.
get_operation_date($p_date, $p_ledger_type, $sql_op)
Get operation from the ledger type before, after or with the given date .
listing()
listing of all ledgers
get_currency()
returns the code iso of the default currency for this ledger
get_propertie()
Get the properties of a journal.
get_class_def()
retrieve the jrn_def_class_deb and return it
previous_amount($p_to)
retrieve amount of previous periode
static next_number($p_cn, $p_type)
retrieve the next number for this type of ledger
input_supplemental_document()
display INPUT type to ask the supplementary documents
select_depot($p_readonly, $p_repo)
Let you select the repository before confirming a sale or a purchase.
verify_autonumber($p_array)
compare given receipt number and suggested one, if different , it means that the user enters a receip...
CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amou...
get_supplier_now()
get info from supplier to pay today
input_paid($p_selected, $p_amount=0, $p_date="", $p_comm="")
Create the section payment.
get_rowSimple($p_from, $p_to, $pa_ledger=[], $trunc=0, $p_limit=-1, $p_offset=-1)
Get simplified row from ledger Call Acc_Ledger_History_Generic:get_rowSimple.
get_customer_late()
get info from customer not yet paid
vat_operation($p_jr_id)
get the amount of vat for a given jr_grpt_id from the table quant_purchase
warn_manual_receipt($p_array)
warn if the suggested receipt and receipt are different , it means that the user tried to number hims...
get_default_card($p_ledger_type, $p_side)
Return an array of default card for the ledger type given.
display_warning($pa_msg, $p_warning)
Display warning contained in an array.
is_enable()
Check if a ledger is enabled , 1 for yes and 0 if disabled.
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.
static array_cat()
create an array of the existing cat, to be used in a checkbox form
get_other_amount($p_jr_id)
get the amount of vat for a given jr_grpt_id from the table quant_purchase
get_name()
Return the name of a ledger.
display_negative_warning($p_amount)
If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
delete_ledger()
delete a ledger IF it doesn't contain anything
convert_from_follow($p_ag_id, $copy_description=0)
convert operations from FOLLOWUP into a SALE , FEENOTE or PURCHASE operation into a suitable array
set_currency_id()
retrieve currency_id from database
set_ledger_id($p_id)
Set the jrn_def.jrn_def_id.
get_type()
Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
get_tiers_id($p_jrn_type, $jr_id)
Return the f_id of the tiers , called by get_tiers.
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
input_additional_tax()
form : display additional tax available for this ledger and value, set 2 values : checkbox if tax app...
verify_operation($p_array)
verify that the operation can be saved
save_new($array)
Insert a new ledger , member variable like jrn_def_id will changed.
find_label($p_value)
Retrieve the label of an accounting.
set_is_loaded($is_loaded)
button_copy_operation()
Show a button to create an operation identical to the recorded one.
get_fiche_def()
retrieve the jrn_def_fiche and return them into a array index deb, cred
verify_ledger($array)
Verify before update.
display_additional_tax($p_additional_tax, $p_amount)
in confirm screen , display the compute value for additional tax @parameter $p_additional_tax acc_oth...
has_quantity()
Check if a ledger is enabled , 1 for yes and 0 if disabled.
reverse($p_date, $p_label)
reverse the operation by creating the opposite one, the result is to avoid it it must be done in
save($p_array=null)
save the operation into the jrnx,jrn, , CA and pre_def
get_solde($p_from, $p_to)
get the saldo of a ledger for a specific period
has_other_tax()
returns true if the ledger has an additional tax
update($array=null)
update a ledger
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
input($p_array=null, $p_readonly=0)
Show the form to encode your operation.
upload_supplemental_document($jr_id)
upload the supplementary documents and attach them to the JRN.JR_ID start a new transaction if the co...
confirm($p_array, $p_readonly=false)
show the result of the array to confirm before inserting
previous_other_tax($p_to)
retrieve the previous amount
save_followup($s_related_action)
attach action-followups to an operation,
get_tiers($p_jrn_type, $jr_id)
Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
__construct($p_cn, $p_id)
construct
get_supplier_late()
get info from supplier not yet paid
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
input_new()
display FORM to enter parameters to create a new ledger.
button_new_operation()
Create a button to encode a new operation into the same ledger.
static test_me($pCase='')
this function is intended to test this class
$jrn_def_negative_warning
get_customer_now()
get info from customer to pay today
guess_pj()
guess what the next pj should be
display_ledger()
display detail of a ledger
select_default_currency()
create a select button to set the default currency for a ledger used only for empty financial ledger
existing_vat()
return the used VAT code with a rate > 0
set_quantity($p_value)
set quantity for the ledger to 1 or 0,
get_ledger_id()
Set the jrn_def.jrn_def_id.
get_last_pj()
returns the sequence number of the receipt for the current ledger or create the sequence if it doesn'...
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
Handle the table payment_method.
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
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
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.
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Manage the TEXTAREA html element.
static icon_add($id, $p_javascript, $p_style="")
static longer($p_domid, $p_size)
Increase size of input_text (p_domid) with p_domid.
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
static show_note($p_domid)
Increase size of input_text (p_domid) with p_domid.
abstract of the table public.jrn_sup_document
ORM abstract of the table public.jrn_def.
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
manage the predefined operation, link to the table op_def and op_def_detail
static available_ledger($get_from_periode)
find all the active ledger for the exerice of the periode and readable by the current user @global ty...
$def
show a form for quick_writing
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
for($e=0; $e< count($afiche); $e++) exit
if( $delta< 0) elseif( $delta==0)
for($i=0;$i< $nb_jrn;$i++) $deb