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';
55 parent::__construct($p_cn,
$p_id);
62 $this->is_loaded=
false;
66 $this->is_loaded=
true;
84 $this->
db->get_value(
"select currency_id from jrn_def where jrn_def_id=$1",
86 if ( $this->currency_id ==
"") {
101 throw new Exception(
_(
"Paramètre invalide"));
103 if ($this->
db->exist_sequence(
"s_jrn_pj".$this->id))
105 $ret=$this->
db->get_array(
"select last_value,is_called from s_jrn_pj".$this->
id);
111 if (
$ret[0][
'is_called']==
'f')
117 $this->
db->create_sequence(
"s_jrn_pj".$this->
id);
146 $this->ledger_name=
_(
" Tous les journaux");
147 $this->ledger_type=
"GL";
151 $Res=$this->
db->exec_sql(
"select jrn_def_type from ".
152 " jrn_def where jrn_def_id=".
158 $this->ledger_type=
$ret[
'jrn_def_type'];
159 return $ret[
'jrn_def_type'];
183 $grpt_id=$this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1',
184 array($this->
jr_id));
185 if ($this->
db->count()==0)
189 $this->
db->exec_sql(
'delete from jrnx where j_grpt=$1', array($grpt_id));
190 $this->
db->exec_sql(
'delete from jrn where jr_id=$1',
191 array($this->
jr_id));
201 $str=
'<p class="notice"> '.$p_warning;
202 $str.=
"<ol class=\"notice\">";
203 for (
$i=0;
$i<count($pa_msg);
$i++)
205 $str.=
"<li>".$pa_msg[
$i].
"</li>";
241 throw new Exception(
_(
"this->jr_id is not set ou opération inconnue"));
247 throw new Exception(
_(
'Date invalide').
$p_date);
252 $grp_new=$this->
db->get_next_seq(
's_grpt');
253 $seq=$this->
db->get_next_seq(
"s_jrn");
255 $this->jr_grpt_id=$this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1',
256 array($this->
jr_id));
257 if ($this->
db->count()==0)
258 throw new Exception(
_(
"Cette opération n'existe pas"));
259 $this->jr_internal=$this->
db->get_value(
'select jr_internal from jrn where jr_id=$1',
260 array($this->
jr_id));
261 if ($this->
db->count()==0||trim($this->jr_internal)==
'')
262 throw new Exception(
_(
"Cette opération n'existe pas"));
265 $per=
new Periode($this->
db);
269 if (
$per->is_open()==0)
271 throw new Exception(
_(
'PERIODE FERMEE').
" $p_date ");
276 if ($this->
db->get_value(
"select count(*) from jrn_note where jr_id=$1",[$this->jr_id])>0){
277 $sql=
"update jrn_note set n_text=$2||n_text where jr_id=$1";
280 $sql=
"insert into jrn_note(n_text,jr_id) values ($1,$2)";
287 throw new Exception(__FILE__.__LINE__.
"sql a echoue [ $sql ]");
293 $a_jid=$this->
db->get_array(
"select j_id,j_debit from jrnx where j_grpt=$1",
294 array($this->jr_grpt_id));
297 for (
$l=0;
$l<count($a_jid);
$l++)
303 $sql=
"insert into jrnx (
304 j_date,j_montant,j_poste,j_grpt,
305 j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode
306 ) select to_date($1,'DD.MM.YYYY'),j_montant,j_poste,$2,
307 j_jrn_def,not (j_debit),j_text,$3,$4,$5,
311 where j_id=$6 returning j_id";
318 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
320 $aj_id=$this->
db->fetch(0);
323 $j_id=$aj_id[
'j_id'];
330 $Res=$this->
db->exec_sql(
"INSERT INTO quant_sold(
331 qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
332 qs_vat_code, qs_client, qs_valid, j_id,qs_vat_sided,qs_unit)
333 SELECT $1, qs_fiche, qs_quantite*(-1), qs_price*(-1), qs_vat*(-1),
334 qs_vat_code, qs_client, qs_valid, $2,qs_vat_sided*(-1),qs_unit*(-1)
335 FROM quant_sold where j_id=$3",
340 throw new Exception(__FILE__.__LINE__.
"sql a echoue [ $sql ]");
342 $Res=$this->
db->exec_sql(
"INSERT INTO quant_purchase(
343 qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
344 qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
345 qp_valid, qp_dep_priv,qp_vat_sided,qp_unit)
346 SELECT $1, $2, qp_fiche, qp_quantite*(-1), qp_price*(-1), qp_vat*(-1),
347 qp_vat_code, qp_nd_amount*(-1), qp_nd_tva*(-1), qp_nd_tva_recup*(-1), qp_supplier,
348 qp_valid, qp_dep_priv*(-1),qp_vat_sided*(-1),qp_unit*(-1)
349 FROM quant_purchase where j_id=$3",
354 throw new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]");
357 $this->
db->exec_sql(
"insert into operation_currency (oc_amount,oc_vat_amount,oc_price_unit,j_id) "
358 .
" select oc_amount,oc_vat_amount,oc_price_unit,$j_id from operation_currency where j_id=$1",
361 $jrn_tax_id=$this->
db->exec_sql(
"insert into jrn_tax(j_id,pcm_val,ac_id)
362 select $j_id,pcm_val,ac_id from jrn_tax where j_id=$1 returning jt_id",
368 if ($anc_group_id == 0 ) $anc_group_id=$this->
db->get_next_seq(
's_oa_group');
369 $this->
db->exec_sql(
"
370 insert into operation_analytique (po_id,oa_amount
383 ,case oa_debit when true then false else true end
385 , to_date($2,'DD.MM.YYYY')
390 ,$anc_group_id from operation_analytique
399 $old_receipt=$this->
db->get_row(
"select jr_pj_number,jr_def_id from jrn where jr_id=$1",[$this->
jr_id]);
400 $sql=
"insert into jrn (
415 select $1,jr_def_id,jr_montant,$7,
416 to_date($2,'DD.MM.YYYY'),$3,$4,
417 $5, true,'EXT',currency_id,currency_rate,currency_rate_ref
420 where jr_id=$6 returning jr_id";
423 $reverse_id=$this->
db->get_value(
$sql,
424 array(
$seq,
$p_date, $grp_new, $p_internal,
$per->p_id, $this->jr_id,$p_label));
426 $reverse_accOp->set_id($reverse_id);
427 $reverse_accOp->pj=$old_receipt[
'jr_pj_number'];
428 $reverse_accOp->jrn=$old_receipt[
'jr_def_id'];
429 $reverse_accOp->update_receipt();
431 }
catch (\Exception
$e){
432 throw new \Exception(
'Echec extourne');
439 $Res=$this->
db->exec_sql(
" INSERT INTO quant_fin(
440 qf_bank, qf_other, qf_amount,jr_id,j_id)
441 SELECT qf_bank, qf_other, qf_amount*(-1),$1,$3
442 FROM quant_fin where jr_id=$2",
446 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR[ $sql ]"));
452 $rec->set_jr_id(
$seq);
453 $rec->insert($this->
jr_id);
458 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
463 $sql=
"delete from stock_goods where sg_id = any ( select sg_id
464 from stock_goods natural join jrnx where j_grpt=$1)";
465 $Res=$this->
db->exec_sql(
$sql,array($this->jr_grpt_id));
468 throw (
new Exception(__FILE__.__LINE__.
"SQL ERROR [ $sql ]"));
479 $this->
db->rollback();
492 $this->ledger_name=
_(
"Grand Livre");
496 $Res=$this->
db->exec_sql(
"select jrn_def_name from ".
497 " jrn_def where jrn_def_id=$1", array($this->
id));
504 $this->ledger_name=
$ret[
'jrn_def_name'];
505 return $ret[
'jrn_def_name'];
519 $pj_pref=
$prop[
"jrn_def_pj_pref"];
520 $padding=
$prop[
'jrn_def_pj_padding'];
522 return $pj_pref.str_pad(
$pj_seq,$padding??0,
'0',STR_PAD_LEFT);
543 $Res=$this->
db->get_row(
"select *
545 where jrn_def_id=$1", array($this->
id));
548 echo
'<DIV="redcontent"><H2 class="error">'._(
'Parametres journaux non trouves').
'</H2> </DIV>';
566 $ledger=
" and j_jrn_def = ".$this->id;
570 $sql=
'select j_montant as montant,j_debit as deb from jrnx where '
581 if (
$line[
'deb']==
't')
635 $sql=
"select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ".
636 " from jrn_def where ".
639 $r=$this->
db->exec_sql(
$sql, array($this->
id));
656 $sql=
"select jrn_def_class_deb ".
657 " from jrn_def where ".
660 $r=$this->
db->exec_sql(
$sql, array($this->
id));
685 return _(
"Aucun résultat");
689 $lPeriode=
new Periode($this->
db);
692 $lPeriode->p_id=$period;
696 $lPeriode->find_periode(
$e_date);
706 _(
"Attention : il vaut mieux utiliser les fiches que les postes comptables"));
709 $ret.=
"<tr><td>"._(
'Date').
" : </td><td>$e_date</td></tr>";
713 $ret.=
"<tr><td>"._(
'Libellé').
" </td><td>".
h(
$desc).
"</td></tr>";
715 $ret.=
_(
'Note').
'</td><td><pre>'.
h(
$p_array[
'jrn_note_input']).
'</pre>';
723 if (
$p_readonly ==
false)
$ret.=
"<tr><td>"._(
'PJ Num').
" </td><td>".
h($e_pj).$span.
"</td></tr>";
724 if (
$p_readonly ==
true )
$ret.=
"<tr><td>"._(
'PJ Num').
" </td><td>".
h($this->pj).$span.
"</td></tr>";
726 $ret.=
"<table class=\"result\">";
728 $ret.=
"<th>"._(
'Quick Code ou ');
729 $ret.=
_(
"Poste").
" </th>";
730 $ret.=
"<th style=\"text-align:left\"> "._(
"Libellé").
" </th>";
731 $ret.=
"<th style=\"text-align:right\">"._(
"Débit").
"</th>";
732 $ret.=
"<th style=\"text-align:right\">"._(
"Crédit").
"</th>";
737 $a_anc=
$anc->get_list();
740 $ret.=
'<th colspan="'.$x.
'" style="width:auto;text-align:center" >'.
_(
'Compt. Analytique').
'</th>';
749 $ret.=HtmlInput::hidden(
'period', $lPeriode->p_id);
750 $ret.=HtmlInput::hidden(
'e_pj', $e_pj);
751 $ret.=HtmlInput::hidden(
'e_pj_suggest', $e_pj_suggest);
752 $ret.=HtmlInput::hidden(
'jrn_note_input',
h(
$p_array[
'jrn_note_input']));
755 $ret.=HtmlInput::hidden(
'mt', $mt);
757 $ret.=HtmlInput::hidden(
'e_comm',
$desc);
759 $ret.=HtmlInput::hidden(
'p_jrn', $this->
id);
760 $ret.=HtmlInput::hidden(
'nb_item', $nb_item);
763 $ret.=HtmlInput::hidden(
'jrn_concerned', $jrn_concerned);
765 $ret.=dossier::hidden();
767 for (
$i=0;
$i<$nb_item;
$i++)
771 if (!isset(${
'qc_'.$i}))
773 if (!isset(${
'poste'.$i}))
775 if (!isset(${
'amount'.$i}))
778 $class=(
$i%2==0)?
' class="even" ':
' class="odd" ';
779 $ret.=
"<tr $class> ";
780 if (trim(${
'qc_'.$i})!=
"")
783 $oqc->get_by_qcode(${
'qc_'.$i},
false);
792 if (trim(${
'qc_'.$i})==
""&&trim(${
'poste'.$i})!=
"")
795 $strPoste=$oposte->id;
796 $ret.=
"<td>".h(${
"poste".$i}.
" - ".
797 $oposte->get_name()).HtmlInput::hidden(
'poste'.
$i,
802 if (trim(${
'qc_'.$i})==
""&&trim(${
'poste'.$i})==
"")
804 $ret.=
"<td>".h(${
"ld".$i}).HtmlInput::hidden(
'ld'.
$i, ${
'ld'.$i});
805 $ret.=(isset(${
"ck$i"}))?HtmlInput::hidden(
'ck'.
$i, ${
'ck'.$i}):
"";
807 if (isset(${
"ck$i"}))
809 $ret.=
"<td class=\"num\">".nbm(${
"amount".$i}).HtmlInput::hidden(
'amount'.
$i,
810 ${
'amount'.$i}).
"</td>".
td(
"");
811 $total_deb=bcadd($total_deb, ${
'amount'.$i});
815 $ret.=
td(
"").
"<td class=\"num\">".
nbm(${
"amount".$i}).HtmlInput::hidden(
'amount'.
$i,
816 ${
'amount'.$i}).
"</td>";
817 $total_cred=bcadd($total_cred, ${
"amount".$i});
829 $ret.=HtmlInput::hidden(
'op[]=',
$i);
831 $ret.=
'<td style="text-align:center">';
834 round(${
'amount'.$i}, 2));
845 $currency_code=
$http->extract(
"p_currency_code",
"number");
846 $currency_rate=
$http->extract(
"p_currency_rate",
"number");
848 $msg_currency= ($currency_code != 0 )?sprintf(
_(
"Totaux %s (%s)"),
$currency->get_code(),$currency_rate):
_(
"Totaux");
850 $ret.=
tr(
td(
'').
td($msg_currency).
td($total_deb,
'class="num"').
td($total_cred,
851 'class="num"'),
'class="highlight"');
853 if ( $currency_code != 0)
855 $currency_rate=
$http->extract(
"p_currency_rate",
"number");
860 td(bcdiv($total_deb,$currency_rate),
'class="num"').
861 td(bcdiv($total_cred,$currency_rate),
'class="num"'),
862 'class="highlight"');
867 $ret.=
'<input type="button" class="button" value="'._(
'verifie Imputation Analytique').
868 '" onClick="verify_ca(\'\');">';
876 $row=$this->
db->get_value(
"select jrn_deb_max_line from jrn_def where jrn_def_id=$1",
901 $add_js=
"update_receipt();";
905 $add_js.=
'get_last_date();';
907 $add_js.=
'update_row("quick_item");';
917 throw new Exception(
_(
'Pas de journal disponible'));
919 $wLedger->javascript=
"onChange='update_name();update_predef(\"ods\",\"t\",\"".$ac.
"\");$add_js'";
920 $label=
" Journal ".Icon_Action::infobulle(2);
929 echo
'<div id="predef_form">';
930 echo HtmlInput::hidden(
'p_jrn_predef', $this->
id);
932 $op->set_p_jrn($this->
id);
933 $op->set_jrn_type(
"ODS");
935 $url=http_build_query(
936 array(
'action'=>
'use_opd',
937 'p_jrn_predef'=>$this->
id,
939 'gDossier'=>dossier::id()));
940 echo
$op->form_get(
'do.php?'.
$url);
943 $str_op_template=ob_get_contents();
946 $ret.=
"<td>"._(
"Modèle d'opération").
"</td>";
947 $ret.=
"<td>".$str_op_template.
"</td>";
963 $l_user_per=
$g_user->get_periode();
973 $l_form_per=$period->input();
978 if (
$e->getCode()==1)
980 echo
_(
"Aucune période ouverte");
985 $f_periode=
td(
_(
"Période comptable").
" $label ").td($l_form_per);
988 $wPJ=
new IText(
'e_pj');
989 $wPJ->readonly=
false;
1000 $wPJ->setReadOnly(
true);
1001 $wPJ->value=$default_pj;
1004 $wPJ->value=(isset($e_pj))?$e_pj:$default_pj;
1008 $ret.=
'<td style="width:auto"> '._(
'Pièce').
' </td> ';
1016 $wDescription=
new IText(
'desc');
1018 $wDescription->size = (empty(
$desc))?60:strlen(
$desc)+5;
1019 $wDescription->size = ($wDescription->size<60)?60:$wDescription->size;
1020 $wDescription->value=(isset(
$desc))?
$desc:
'';
1021 $ret.=$wDescription->input();
1030 $ret.=
'<td> <pre id="jrn_note_td"></pre></td>';
1032 $currency_select = $this->
CurrencyInput(
"currency_code",
"p_currency_rate" ,
"p_currency_euro");
1033 $currency_select->selected=
$http->request(
'p_currency_code',
'string',0);
1035 $currency_input=
new INum(
"p_currency_rate");
1036 $currency_input->prec=8;
1037 $currency_input->id=
"p_currency_rate";
1038 $currency_input->value=
$http->request(
'p_currency_rate',
'string',1);
1039 $ret.=
tr(
td(
_(
"Devise")).
td($currency_select->input().
1040 $currency_input->change(
'CurrencyComputeMisc(\'p_currency_rate\',\'p_currency_euro\');')));
1047 $note = (isset(
$p_array[
'jrn_note_input'])) ?
$p_array[
'jrn_note_input'] :
'';
1050 $ret.=ob_get_contents();
1053 $ret.=HtmlInput::hidden(
'e_pj_suggest', $default_pj);
1060 $ret.=dossier::hidden();
1061 $ret.=HtmlInput::hidden(
'jrn_type', $this->
get_type());
1064 $ret.=
'<table id="quick_item" style="width:100%">';
1066 '<th style="text-align:left">Quickcode'.$info.
'</th>'.
1067 '<th style="text-align:left">'._(
'Poste').$info_poste.
'</th>'.
1068 '<th class="visible_gt800 visible_gt1155" style="text-align:left">'._(
'Libellé').
'</th>'.
1069 '<th style="text-align:left">'._(
'Montant').
'</th>'.
1070 '<th style="text-align:left">'._(
'Côté').
'</th>'.
1078 $quick_code->set_dblclick(
"fill_ipopcard(this);");
1090 $quick_code->javascript=sprintf(
' onchange="fill_data_onchange(\'%s\');" ',
1093 $quick_code->value=(isset(${
'qc_'.$i}))?${
'qc_'.$i}:
"";
1109 $poste->set_attribute(
'ipopup',
'ipop_account');
1110 $poste->set_attribute(
'label',
'ld'.
$i);
1111 $poste->set_attribute(
'account',
'poste'.
$i);
1112 $poste->set_attribute(
'dossier', Dossier::id());
1114 $poste->value=(isset(${
'poste'.$i}))?${
"poste".$i}:
''
1116 $poste->dbl_click_history();
1123 $label=$Poste->get_lib();
1127 $line_desc=
new IText();
1128 $line_desc->name=
'ld'.$i;
1129 $line_desc->size=30;
1130 $line_desc->value=(isset(${
"ld".$i}))?${
"ld".$i}:
1137 $amount->value=(isset(${
'amount'.$i}))?${
"amount".$i}:
''
1140 $amount->javascript=
'onChange="format_number(this);checkTotalDirect()"';
1144 $deb->selected=(isset(${
'ck'.$i}))?
true:
false;
1146 $deb->javascript=
'class="debit-credit" onChange="checkTotalDirect()"';
1147 $str_add_button=($add_card==
true)?$this->
add_card(
"-1",
1150 $ret.=
'<td>'.$quick_code->input().$quick_code->search().$str_add_button.
'</td>';
1151 $ret.=
'<td>'.$poste->input().
1153 'document.getElementById(\'poste'.$i.
'\').onblur=
function(){
'.
1154 'if (trim(this.
value) !=\
'\')
'.
1155 '{document.getElementById(\
'qc_'.
$i.
'\').value=
"";}}
'.
1158 $ret.='<
td class=
"visible_gt800 visible_gt1155">
'.$line_desc->input().'</
td>
';
1159 $ret.='<
td>
'.$amount->input().'</
td>
';
1160 $ret.='<
td>
'.$deb->input()
1161 .'<
span id=
"txt'.$deb->id.'"></
span>
'
1164 // If readonly == 1 then show CA
1167 if (isset($this->with_concerned)&&$this->with_concerned==true)
1169 $oRapt=new Acc_Reconciliation($this->db);
1170 $w=$oRapt->widget();
1171 $w->name='jrn_concerned
';
1172 $w->value=(isset($jrn_concerned))?$jrn_concerned:"";
1173 $ret.=sprintf(_("Réconciliation/rapprochements : %s"), $w->input());
1175 $ret.=create_script("$('".$wDate->id."').focus()");
1176 // for displaying Credit or Debit
1177 $ret.=create_script("(function(){activate_checkbox_side()})();");
1188 function is_closed($p_periode)
1190 $per=new Periode($this->db);
1191 $per->set_ledger($this->id);
1192 $per->set_periode($p_periode);
1193 $ret=$per->is_closed();
1207 function verify_operation($p_array)
1209 global $g_parameter;
1210 $http=new HttpInput();
1211 if (is_array($p_array)==false||empty($p_array))
1212 throw new Exception("Array empty");
1214 * Check needed value
1216 check_parameter($p_array, 'p_jrn,e_date
');
1218 extract($p_array, EXTR_SKIP);
1223 $http->set_array($p_array);
1224 /* Check currency : rate cannot be equal to 0 */
1225 $currency_rate=$http->extract("p_currency_rate","number");
1226 if ( $currency_rate <=0 ) {
1227 throw new Exception(_("Taux de conversion doit être supérieur à 0"),3);
1229 /* Check currency : Does the currency parameter exist */
1230 $currency_code=$http->extract("p_currency_code","number");
1231 $currency=new Acc_Currency($this->db,$currency_code);
1233 $this->check_currency_setting($currency_code);
1235 /* check if we can write into this ledger */
1236 if ($g_user->check_jrn($p_jrn)!='W
')
1237 throw new Exception(_('Accès interdit
'), 20);
1239 /* check for a double reload */
1240 if (isset($mt)&&$this->db->count_sql('select jr_mt
from jrn where jr_mt=$1
',
1242 throw new Exception(_('Double Encodage
'), 5);
1244 // Check the periode and the date
1245 if (isDate($e_date)==null)
1247 throw new Exception(_('Date invalide
'), 2);
1249 $periode=new Periode($this->db);
1250 /* find the periode if we have enabled the check_periode
1251 * or if period is not set
1253 if ($this->check_periode()==false||!isset($p_array['period
']))
1256 $periode->find_periode($e_date);
1257 } catch (Exception $e) {
1258 throw new Exception(_("Période inexistante"), 6, $e);
1263 $periode->p_id=$p_array['period
'];
1264 list ($min, $max)=$periode->get_date_limit();
1265 if (cmpDate($e_date, $min)<0||
1266 cmpDate($e_date, $max)>0)
1267 throw new Exception(_('Date et periode ne correspondent pas
'), 6);
1273 if ($this->is_closed($periode->p_id)==1)
1275 throw new Exception(_('Periode fermee
'), 6);
1277 /* check if we are using the strict mode */
1278 if ($this->check_strict()==true)
1280 /* if we use the strict mode, we get the date of the last
1282 $last_date=$this->get_last_date();
1283 if ($last_date!=null&&cmpDate($e_date, $last_date)<0)
1284 throw new Exception(
1286 _('Vous utilisez le mode strict la dernière operation est la date du %s
1287 vous ne pouvez pas encoder à une date antérieure
'),$last_date),
1291 for ($i=0; $i<$nb_item; $i++)
1295 // compatibily php 8.0 , if $amount is not a number then skip
1296 if (!isset(${'amount
'.$i}) || isNumber(${'amount
'.$i})==0) {
1300 // Check the balance
1301 $amount=round(${'amount
'.$i}, 2);
1302 $tot_deb+=(isset(${'ck
'.$i}))?$amount:0;
1303 $tot_cred+=(!isset(${'ck
'.$i}))?$amount:0;
1305 // Check if the card is permitted
1306 if (isset(${'qc_
'.$i})&&trim(${'qc_
'.$i})!="")
1308 $f=new Fiche($this->db);
1309 $f->get_by_qcode(${'qc_
'.$i});
1310 $f->quick_code=${'qc_
'.$i};
1312 if ($f->get_f_enable() == '0
')
1313 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée
"),${'qc_'.$i}), 50);
1314 if ($f->belong_ledger($p_jrn) < 1 )
1315 throw new Exception("La fiche quick_code =
".
1316 $f->quick_code." n'est pas dans ce journal", 4);
1317 if (noalyss_strlentrim(${'qc_
'.$i})!=0&&isNumber(${'amount
'.$i})==0)
1318 throw new Exception(_('Montant invalide
'), 3);
1320 $strPoste=$f->strAttribut(ATTR_DEF_ACCOUNT);
1322 throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable
"),
1325 $p=new Acc_Account_Ledger($this->db, $strPoste);
1326 if ($p->do_exist()==0)
1327 throw new Exception(_('Poste Inexistant pour la fiche ['.${'qc_'.$i}.']'),
1331 // Check if the account is permitted
1332 if (isset(${'poste'.$i})&&noalyss_strlentrim(${'poste'.$i})!=0)
1334 $p=new Acc_Account_Ledger($this->db, ${'poste'.$i});
1335 if ($p->belong_ledger($p_jrn)<0) {
1336 throw new Exception(sprintf (
1337 _("Le poste %s
n'est pas dans ce journal",$p->id)),
1340 if (noalyss_strlentrim(${'poste
'.$i})!=0&&isNumber(${'amount
'.$i})==0)
1341 throw new Exception(_('Poste invalide [
'.${'poste
'.$i}.']
'),
1343 if ($p->do_exist()==0)
1344 throw new Exception(_('Poste Inexistant [
'.${'poste
'.$i}.']
'),
1346 $card_id=$p->find_card();
1347 if (!empty($card_id))
1349 $str_msg=sprintf(_(" Le poste %s appartient à fiche(s) dont : %s"),$p->id,count($card_id));
1350 $max=(count($card_id)>MAX_COMPTE_CARD)?MAX_COMPTE_CARD:count($card_id);
1351 for ($x=0; $x<$max; $x++)
1353 $card=new Fiche($this->db, $card_id[$x]['f_id
']);
1354 $str_msg.=HtmlInput::card_detail($card->strAttribut(ATTR_DEF_QUICKCODE),
1355 $card->strAttribut(ATTR_DEF_NAME),
1356 'style=
"color:red;display:inline;text-decoration:underline"');
1361 $account=new Acc_Account($this->db,${"poste".$i});
1362 if ( $account->get_parameter("pcm_direct_use") == "N") {
1363 throw new Exception(sprintf (_("Utilisation directe interdite du poste comptable %s"), ${"poste".$i}));
1367 $tot_deb=round($tot_deb, 4);
1368 $tot_cred=round($tot_cred, 4);
1369 if ($tot_deb!=$tot_cred)
1371 throw new Exception(_("Balance incorrecte ")." debit = $tot_deb credit=$tot_cred ",
1388 function compute_internal_code($p_grpt)
1392 $num=$this->db->get_next_seq('s_internal
');
1393 $atype=$this->get_propertie();
1394 $type=substr($atype['jrn_def_code
'], 0, 1);
1395 $internal_code=sprintf("%s%06X", $type, $num);
1396 $this->jr_internal=$internal_code;
1397 return $internal_code;
1408 function save($p_array=null)
1412 throw new Exception('
save cannot use a empty array
');
1414 global $g_parameter;
1416 $http=new HttpInput();
1417 extract($p_array, EXTR_SKIP);
1418 if ( !isset($p_array['jrn_note_input
'])) {$p_array['jrn_note_input
']='';}
1421 $msg=$this->verify($p_array);
1424 echo $this->display_warning($msg,
1425 _("Attention : il vaut mieux utiliser les fiches que les postes comptables "));
1429 $seq=$this->db->get_next_seq('s_grpt
');
1430 $internal=$this->compute_internal_code($seq);
1432 $group=$this->db->get_next_seq("s_oa_group");
1436 $oPeriode=new Periode($this->db);
1437 $check_periode=$this->check_periode();
1438 if ($check_periode==false||!isset($p_array['period
']))
1440 $oPeriode->find_periode($e_date);
1444 $oPeriode->id=$period;
1450 $http->set_array($p_array);
1451 $currency_code=$http->extract( "p_currency_code","number",0);
1452 $currency_rate=$http->extract( "p_currency_rate","number",1);
1453 $currency_rate_ref=new Acc_Currency($this->db, $currency_code);
1455 for ($i=0; $i<$nb_item; $i++)
1457 if (!isset(${'qc_
'.$i})&&!isset(${'poste
'.$i}))
1459 $acc_op=new Acc_Operation($this->db);
1461 // First we save the jrnx
1462 if (isset(${'qc_
'.$i}))
1464 $qc=new Fiche($this->db);
1465 $qc->get_by_qcode(${'qc_
'.$i}, false);
1466 $sposte=$qc->strAttribut(ATTR_DEF_ACCOUNT);
1467 /* if there are 2 accounts take following the deb or cred */
1468 if (strpos($sposte, ',
')!=0)
1470 $array=explode(",", $sposte);
1471 $poste=(isset(${'ck
'.$i}))?$array[0]:$array[1];
1477 throw new Exception(sprintf(_("La fiche %s n'a pas de poste comptable
"),
1480 $quick_code=${'qc_'.$i};
1484 $poste=${'poste'.$i};
1487 $acc_op->date=$e_date;
1488 // compute the periode is do not check it
1489 if ($check_periode==false)
1490 $acc_op->periode=$oPeriode->p_id;
1492 if (noalyss_strlentrim(${'ld'.$i})!=0)
1493 $acc_op->desc=${'ld'.$i};
1495 // Amount in default currency , usually EUR
1496 $acc_op->amount=round(bcdiv(${'amount'.$i},$currency_rate),2);
1498 $acc_op->poste=$poste;
1499 $acc_op->jrn=$this->id;
1500 $acc_op->type=(isset(${'ck'.$i}))?'d':'c';
1501 $acc_op->qcode=$quick_code;
1502 $j_id=$acc_op->insert_jrnx();
1505 $operation_currency=new Operation_currency_SQL($this->db);
1506 if (isNumber(${'amount'.$i}) == 0) {
1507 $operation_currency->oc_amount=0;
1509 $operation_currency->oc_amount=round(${'amount'.$i}, 2);
1511 $operation_currency->oc_vat_amount=0;
1512 $operation_currency->oc_price_unit=0;
1513 $operation_currency->j_id=$j_id;
1514 $operation_currency->insert();
1516 $tot_amount=bcadd($tot_amount,round($acc_op->amount, 2));
1518 if ( $acc_op->type == 'd') {
1519 $tot_deb=bcadd($tot_deb, $acc_op->amount);
1520 }elseif ( $acc_op->type == 'c') {
1521 $tot_cred=bcadd($tot_cred,$acc_op->amount);
1524 if ($g_parameter->MY_ANALYTIC!="nu
")
1526 if ($g_parameter->match_analytic( $poste)==TRUE)
1529 // for each item, insert into operation_analytique */
1530 $op=new Anc_Operation($this->db);
1531 $op->set_currency_rate($currency_rate);
1532 $op->oa_group=$group;
1534 $op->oa_date=$e_date;
1535 $op->oa_debit=($acc_op->type=='d' )?'t':'f';
1536 $op->oa_description=$desc;
1538 // send the amount in default currency to analytic
1540 $an_array['amount'.$i]=$acc_op->amount;
1541 $op->save_form_plan($an_array, $count, $j_id);
1545 }// loop for each item
1546 $acc_end=new Acc_Operation($this->db);
1547 // Check the balance
1548 if ( bcsub($tot_deb,$tot_cred,2) != 0 && $currency_code != 0)
1551 $diff=bcsub($tot_cred, $tot_deb);
1552 // store the difference in currency_rounded_delta
1553 $poste_cred = $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED;
1557 $poste=$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB;
1562 // insert difference of change
1563 $acc_change=new Acc_Operation($this->db);
1564 $acc_change->amount=abs($diff);
1565 $acc_change->grpt=$seq;
1566 $acc_change->poste=$poste;
1567 $acc_change->jrn=$this->id;
1568 $acc_change->type=$side;
1569 $acc_change->date=$e_date;
1570 $acc_change->desc=_("Différence de change
");
1572 $change_j_id=$acc_change->insert_jrnx();
1574 $tot_deb=bcadd($tot_deb,$diff);
1577 $acc_end->amount=$tot_deb;
1578 if ($check_periode==false)
1580 $acc_end->periode=$oPeriode->p_id;
1582 $acc_end->date=$e_date;
1583 $acc_end->desc=$desc;
1584 $acc_end->grpt=$seq;
1585 $acc_end->jrn=$this->id;
1587 $acc_end->jr_optype=$jr_optype;
1588 $acc_end->currency_id=$currency_code;
1589 $acc_end->currency_rate=$currency_rate;
1590 $acc_end->currency_rate_ref=$currency_rate_ref->get_rate();
1592 $jr_id=$acc_end->insert_jrn();
1594 $this->jr_id=$jr_id;
1596 throw new Exception(_('Balance incorrecte'));
1598 $this->pj=$acc_end->update_receipt();
1599 /* if e_suggest != e_pj then do not increment sequence */
1600 if ($this->pj == $e_pj_suggest &&noalyss_strlentrim($e_pj)!=0)
1602 $this->inc_seq_pj();
1607 $this->db->exec_sql("update jrn set jr_internal=$1
1608 where jr_grpt_id = $2
",array($internal,$seq));
1610 $this->internal=$internal;
1611 // Save now the predef op
1612 //------------------------
1613 if (isset($opd_name)&&trim($opd_name)!="")
1615 $opd=new Pre_operation($this->db);
1616 $opd->set_od_direct('t');
1621 if (isset($this->with_concerned)&&$this->with_concerned==true)
1623 $orap=new acc_reconciliation($this->db);
1624 $orap->jr_id=$jr_id;
1626 $orap->insert($jrn_concerned);
1631 if (isset($_FILES["pj
"]))
1633 $this->db->save_receipt($seq);
1635 /*----------------------------------------------
1637 ----------------------------------------------*/
1638 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
1639 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
1640 $acc_operation_note->setNote($p_array['jrn_note_input']);
1641 $acc_operation_note->setOperation_id( $jr_id);
1642 $acc_operation_note->save();
1645 catch (Exception $e)
1648 $this->db->rollback();
1649 echo_warning(_('OPERATION ANNULEE voir log'));
1652 $this->db->commit();
1665 static function next_number($p_cn, $p_type)
1668 $Ret=$p_cn->count_sql("select *
from jrn_def where jrn_def_type=
'".$p_type."'");
1677 public function get_first($p_type, $p_access=3)
1680 $all=$g_user->get_ledger($p_type, $p_access,false);
1681 if (empty ($all)) return NULL;
1689 function update_paid($p_array)
1691 // reset all the paid flag because the checkbox is post only
1693 foreach ($p_array as $name=> $paid)
1695 list($ad)=sscanf($name, "set_jr_id%d
");
1699 $Res=$this->db->exec_sql($sql);
1701 // set a paid flag for the checked box
1702 foreach ($p_array as $name=> $paid)
1704 list ($id)=sscanf($name, "rd_paid%d
");
1709 $Res=$this->db->exec_sql($sql);
1713 function update_internal_code($p_internal)
1715 if (!isset($this->grpt_id))
1716 throw new Exception(('ERREUR '.__FILE__.":
".__LINE__));
1717 $Res=$this->db->exec_sql("update jrn set jr_internal=$1 where
1718 jr_grpt_id = $2
",array($p_internal,$this->grpt_id));
1727 function get_default_card($p_ledger_type, $p_side)
1730 $fiche_def_ref=new Fiche_Def_Ref($this->db);
1731 // ----- for FINANCIAL ----
1732 if ($p_ledger_type=='FIN')
1734 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
1735 $array=array_merge($array,
1736 $fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
1737 $array=array_merge($array,
1738 $fiche_def_ref->get_by_modele(FICHE_TYPE_FIN));
1739 $array=array_merge($array,
1740 $fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
1741 $array=array_merge($array,
1742 $fiche_def_ref->get_by_modele(FICHE_TYPE_EMPL));
1744 // --- for miscellaneous ----
1745 if ($p_ledger_type=='ODS')
1747 $result=$this->db->get_array('select fd_id from fiche_def');
1748 for ($i=0; $i<count($result); $i++)
1750 $array[$i]=$result[$i]['fd_id'];
1755 switch ($p_ledger_type)
1758 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_CLIENT);
1761 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_SER);
1762 $array=array_merge($array,
1763 $fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAR));
1764 $array=array_merge($array,
1765 $fiche_def_ref->get_by_modele(FICHE_TYPE_ACH_MAT));
1768 throw new Exception(_('get_default_card p_ledger_side is invalide ['.$p_ledger_type.']'));
1771 elseif ($p_side=='C')
1773 switch ($p_ledger_type)
1776 $array=$fiche_def_ref->get_by_modele(FICHE_TYPE_VENTE);
1779 $array=array_merge($array,
1780 $fiche_def_ref->get_by_modele(FICHE_TYPE_ADM_TAX));
1781 $array=array_merge($array,
1782 $fiche_def_ref->get_by_modele(FICHE_TYPE_FOURNISSEUR));
1785 throw new Exception(_('get_default_card p_ledger_side is invalide ['.$p_ledger_type.']'));
1791 $return = array_values($array);
1792 for ($i = 0;$i<count($array);$i++ )
1794 $return[$i]=$array[$i]['fd_id'];
1806 function get_all_fiche_def()
1808 $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred
".
1809 " from jrn_def where
".
1812 $r=$this->db->exec_sql($sql, array($this->id));
1814 $res=Database::fetch_all($r);
1819 foreach ($res as $item)
1821 if (noalyss_strlentrim($item['deb'])!=0)
1823 $card.=$comma.$item['deb'];
1826 if (strlen(noalyss_trim($item['cred']))!=0)
1828 $card.=$comma.$item['cred'];
1840 function check_strict()
1842 global $g_parameter;
1843 if ($g_parameter->MY_STRICT=='Y')
1845 if ($g_parameter->MY_STRICT=='N')
1847 throw new Exception("Valeur invalid
".__FILE__.':'.__LINE__);
1855 function check_periode()
1857 global $g_parameter;
1858 if ($g_parameter->MY_CHECK_PERIODE=='Y')
1860 if ($g_parameter->MY_CHECK_PERIODE=='N')
1862 throw new Exception("Valeur invalid
".__FILE__.':'.__LINE__);
1870 function check_currency_setting ($p_currency_code)
1872 global $g_parameter;
1873 if ( $p_currency_code == -1 )
1875 throw new Exception(_('Devise inconnue'), 3);
1877 /* -- check the accounting for error of exchange -*/
1878 if ($p_currency_code > 0 )
1880 $poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
1882 if ($poste->get_parameter("
id") == -1 )
1884 throw new Exception(
1885 sprintf(_("Dans COMPANY, vous
n'avez pas paramétré correctement ".
1886 " le compte de débit %s pour les erreurs de conversion"),
1887 $g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
1890 $poste=new Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
1891 if ($poste->get_parameter("id") == -1 )
1893 throw new Exception(
1894 sprintf(_("Dans COMPANY, vous n'avez pas paramétré correctement
".
1895 " le compte de crédit %s pour les erreurs de conversion
"),
1896 $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
1910 function check_currency($p_qcode_payment, $p_currency_id)
1912 $card=new Fiche($this->db);
1913 $card->get_by_qcode($p_qcode_payment);
1914 if ( $card->id == 0) throw new Exception (_("
Fiche invalide
"));
1916 $ledger = $card->get_bank_ledger();
1917 if ( $ledger != NULL )
1919 $ledger_currency_id=$ledger->get_currency()->get_id();
1920 // if sale and payment are not the same currency and the
1921 if ($ledger_currency_id != 0 && $p_currency_id != $ledger_currency_id )
1923 throw new Exception (_("Devise de la banque doit être identique à l
'opération"));
1930 function get_last_date()
1933 throw new Exception(__FILE__.":".__LINE__."Journal incorrect ");
1934 $sql="select to_char(max(jr_date),'DD.MM.YYYY
') from jrn where jr_def_id=$1";
1935 $date=$this->db->get_value($sql, array($this->id));
1945 function get_id($p_internal)
1948 $value=$this->db->get_value($sql, array($p_internal));
1961 function create_document($internal, $p_array)
1963 extract($p_array, EXTR_SKIP);
1964 $doc=new Document($this->db);
1965 $doc->f_id=$e_client;
1966 $doc->md_id=$gen_doc;
1968 $p_array['e_pj
']=$this->pj;
1970 $doc->Generate($p_array, $p_array['e_pj
']);
1971 // Move the document to the jrn
1972 $doc->moveDocumentPj($internal);
1973 // Update the comment with invoice number, if the comment is empty
1974 if (!isset($e_comm)||noalyss_strlentrim($e_comm)==0)
1976 $sql="update jrn set jr_comment=' document
".$doc->d_number."' where jr_internal='$internal
'";
1977 $this->db->exec_sql($sql);
1979 return h($doc->d_name.' (
'.$doc->d_filename.')
');
1987 public function check_payment($e_mp, $e_mp_qcode)
1989 /* Check if the "paid by" is empty, */
1992 /* the paid by is not empty then check if valid */
1993 $empl=new Fiche($this->db);
1994 $empl->get_by_qcode($e_mp_qcode);
1995 if ($empl->empty_attribute(ATTR_DEF_ACCOUNT)==true)
1997 throw new Exception(_("Le moyen de paiement choisi n'a pas de poste comptable
"),
2000 /* get the account and explode if necessary */
2001 $sposte=$empl->strAttribut(ATTR_DEF_ACCOUNT);
2002 // if 2 accounts, take only the debit one for customer
2003 if (strpos($sposte, ',')!=0)
2005 $array=explode(',', $sposte);
2006 $poste_val=$array[0];
2012 $poste=new Acc_Account_Ledger($this->db, $poste_val);
2013 if ($poste->load()==false)
2015 throw new Exception(sprintf(_("Pour la fiche %s le poste comptable [%s]
n'existe pas"),
2016 $empl->quick_code, $poste->id), 9);
2023 function inc_seq_pj()
2025 $sql="select nextval('s_jrn_pj
".$this->id."')";
2026 $this->db->exec_sql($sql);
2036 function get_last($p_limit)
2039 $filter_ledger=$g_user->get_ledger_sql('
ALL', 3);
2040 $filter_ledger=noalyss_str_replace('jrn_def_id', 'jr_def_id
', $filter_ledger);
2042 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
2044 join jrn_def on (jrn_def_id=jr_def_id)
2045 where $filter_ledger
2046 order by jr_date desc , substring(jr_pj_number,'[0-9]+$
')::numeric desc limit $p_limit";
2047 $array=$this->db->get_array($sql);
2058 function search_group($p_what, $p_value)
2063 return $this->db->get_value('select jr_grpt_id
from jrn where jr_internal=$1
',
2073 function get_operation($p_from, $p_to)
2076 $jrn=($this->id==0)?'and
'.$g_user->get_ledger_sql():' and jr_def_id =
'.$this->id;
2077 $sql="select jr_id as id ,jr_internal as internal, ".
2078 "jr_pj_number as pj,jr_grpt_id,".
2079 " to_char(jr_date,'DDMMYY
') as date_fmt, ".
2080 " jr_comment as comment, jr_montant as montant ,".
2081 " jr_grpt_id,jr_def_id,jrn.currency_id,currency_rate,currency_rate_ref,cr_code_iso ".
2082 " from jrn join jrn_def on (jr_def_id=jrn_def_id) ".
2083 " left join currency on (currency.id=jrn.currency_id) ".
2085 " jr_date >= (select p_start from parm_periode where p_id = $1)
2086 and jr_date <= (select p_end from parm_periode where p_id = $2)".
2087 ' '.$jrn.' order by jr_date,substring(jr_pj_number,\
'[0-9]+$\')::numeric asc';
2088 $ret=$this->
db->get_array(
$sql, array($p_from, $p_to));
2101 $array=$this->
db->get_array(
"select tva_id,tva_label,tva_poste
2103 where tva_rate != 0.0000
2104 and exists (select qp_vat_code from quant_purchase
2107 and exists (select j_id
2108 from jrnx where j_jrn_def = $1))
2114 $array=$this->
db->get_array(
"select tva_id,tva_label,tva_poste
2116 where tva_rate != 0.0000
2117 and exists (select qs_vat_code from quant_sold
2118 where qs_vat_code=tva_id
2120 exists (select j_id from jrnx where j_jrn_def = $1))
2147 $array=$this->
db->get_array(
'select sum(qp_price) as price,sum(qp_vat) as vat '.
2148 ',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv'.
2149 ',sum(coalesce(qp_nd_tva_recup,0)+coalesce(qp_nd_tva,0)) as tva_nd'.
2150 ',sum(qp_vat_sided) as tva_np'.
2151 ' from quant_purchase join jrnx using(j_id)
2152 where j_grpt=$1 ', array($p_jr_id));
2157 $array=$this->
db->get_array(
'select sum(qs_price) as price,sum(qs_vat) as vat '.
2160 ',sum(qs_vat_sided) as tva_np'.
2161 ' from quant_sold join jrnx using(j_id)
2162 where j_grpt=$1 ', array($p_jr_id));
2183 $array=$this->
db->get_array(
'select coalesce(sum(qp_vat),0) as sum_vat,tva_id
2184 from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
2185 where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
2190 $array=$this->
db->get_array(
'select coalesce(sum(qs_vat),0) as sum_vat,tva_id
2191 from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
2192 where tva_rate !=0.0 and j_grpt=$1 group by tva_id',
2231 $exercise=
$periode->get_exercice();
2234 $min_date=
$min->first_day();
2236 $periode_max=
new Periode($this->
db, $p_to);
2237 $max_date=$periode_max->first_day();
2243 $sql=
"select coalesce(sum(qp_price),0) as price".
2244 " ,coalesce(sum(qp_vat),0) as vat ".
2245 ',coalesce(sum(qp_dep_priv),0) as priv'.
2246 ',coalesce(sum(qp_vat_sided),0) as reversed'.
2247 ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd'.
2248 ',coalesce(sum(qp_vat_sided),0) as tva_np'.
2249 ' from quant_purchase join jrnx using(j_id) '.
2250 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
2251 ' and j_jrn_def = $3';
2253 array($min_date, $max_date, $this->
id));
2257 $array=$this->
db->get_array(
"select coalesce(sum(qp_vat),0) as sum_vat,tva_id
2258 from quant_purchase as p
2259 right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
2262 and j_date >= to_date($1,'DD.MM.YYYY')
2263 and j_date < to_date($2,'DD.MM.YYYY')
2266 array($min_date, $max_date, $this->
id));
2272 $sql=
"select coalesce(sum(qs_price),0) as price".
2273 " ,coalesce(sum(qs_vat),0) as vat ".
2276 ',coalesce(sum(qs_vat_sided),0) as reversed'.
2278 ' from quant_sold join jrnx using(j_id) '.
2279 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
2280 ' and j_jrn_def = $3';
2282 array($min_date, $max_date, $this->
id));
2285 $array=$this->
db->get_array(
"select coalesce(sum(qs_vat),0) as sum_vat,tva_id
2286 from quant_sold as p
2287 right join tva_rate on (qs_vat_code=tva_id)
2288 join jrnx using(j_id)
2291 j_date >= to_date($1,'DD.MM.YYYY')
2292 and j_date < to_date($2,'DD.MM.YYYY')
2295 array($min_date, $max_date, $this->
id));
2310 if ( $min_date <> $max_date)
2312 $cond=sprintf(
"j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ",
2313 $min_date,$max_date);
2315 $cond=sprintf(
"j_date = to_date('%s','DD.MM.YYYY') ",
2318 $saldo=$bank_card->get_bk_balance($cond);
2331 $exercise=
$periode->get_exercice();
2334 $min_date=
$min->first_day();
2336 $periode_max=
new Periode($this->
db, $p_to);
2337 $max_date=$periode_max->first_day();
2346 join jrnx using(j_id)
2347 join jrn_tax using (j_id)
2348 where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
2349 and j_jrn_def = $3";
2351 array($min_date, $max_date, $this->
id));
2353 return array(
'other_tax_amount',
$amount);
2362 join jrnx using(j_id)
2363 join jrn_tax using (j_id)
2364 where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
2365 and j_jrn_def = $3";
2367 array($min_date, $max_date, $this->
id));
2369 return array(
'other_tax_amount',
$amount);
2372 return array(
'other_tax_amount',0);
2384 echo Acc_Reconciliation::$javascript;
2386 $cn=Dossier::connect();
2388 $_SESSION[SESSION_KEY.
'g_pass']=
'phpcompta';
2392 $a->with_concerned=
true;
2394 echo
'<FORM method="post">';
2395 echo
$a->select_ledger()->input();
2396 echo HtmlInput::submit(
'go',
'Test it');
2401 echo
'<form method="post">';
2402 echo
$a->show_form();
2403 echo HtmlInput::submit(
'post_id',
'Try me');
2408 echo dossier::hidden();
2409 echo
'<input type="hidden" value="'.$id.
'" name="p_jrn">';
2413 if (
$op->count()!=0)
2415 echo HtmlInput::submit(
'use_opd',
2416 'Utilisez une opération prédéfinie',
2418 echo
$op->show_button();
2424 if (isset(
$_POST[
'post_id']))
2427 echo
'<form method="post">';
2429 echo HtmlInput::button(
'add',
'Ajout d\'une ligne',
2430 'onClick="quick_writing_add_row()"');
2431 echo HtmlInput::submit(
'save_it',
_(
"Sauver"));
2435 if (isset(
$_POST[
'save_it']))
2444 catch (Exception
$e)
2447 echo
'<form method="post">';
2450 echo HtmlInput::submit(
'post_id',
'Try me');
2457 if (isset(
$_GET[
'use_opd']))
2459 $op=
new Pre_op_advanced(
$cn);
2465 echo
'<FORM method="post">';
2468 echo HtmlInput::submit(
'post_id',
'Use predefined operation');
2475 if ($pCase==
'search')
2478 $cn=Dossier::connect();
2481 $_SESSION[SESSION_KEY.
'g_pass']=
'phpcompta';
2482 echo
$ledger->search_form(
'ALL');
2488 if ($pCase==
'reverse')
2490 $cn=Dossier::connect();
2491 $jr_internal=
'OD-01-272';
2495 $jrn_def_id=
$cn->get_value(
'select jr_def_id from jrn where jr_internal=$1',
2496 array($jr_internal));
2498 $ledger->jr_id=
$cn->get_value(
'select jr_id from jrn where jr_internal=$1',
2499 array($jr_internal));
2501 echo
"Ouvrez le fichier ".__FILE__.
" à la ligne ".__LINE__.
" pour changer jr_internal et vérifier le résultat de l'extourne";
2503 $ledger->reverse(
'01.07.2010');
2505 catch (Exception
$e)
2521 array(
'cat'=>
'VEN',
'name'=>
_(
"Journaux de vente")),
2522 array(
'cat'=>
'ACH',
'name'=>
_(
"Journaux d'achat")),
2523 array(
'cat'=>
'FIN',
'name'=>
_(
"Journaux Financier")),
2524 array(
'cat'=>
'ODS',
'name'=>
_(
"Journaux d'Opérations diverses"))
2537 switch ($p_jrn_type)
2540 $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',
2544 $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',
2549 $tiers=$this->
db->get_value(
'select qf_other from quant_fin where jr_id=$1',
2553 if ($this->
db->count()==0)
2565 if ($p_jrn_type==
'ODS')
2571 $name=$this->
db->get_value(
'select ad_value from fiche_detail where ad_id=1 and f_id=$1',
2573 $first_name=$this->
db->get_value(
'select ad_value from fiche_detail where ad_id=32 and f_id=$1',
2575 return $name.
' '.$first_name;
2585 $base_url=
"?".dossier::get().
"&ac=".
$_REQUEST[
'ac'];
2588 $r.=
_(
'Cherche').
" ".HtmlInput::filter_table(
"cfgledger_table_id",
"0",
2590 $r.=
'<TABLE id="cfgledger_table_id" class="vert_mtitle">';
2591 $r.=
'<TR><TD class="first"><A HREF="'.$base_url.
'&sa=add">'.
_(
'Ajout journal').
' </A></TD></TR>';
2592 $ret=$this->
db->exec_sql(
"select distinct jrn_def_id,jrn_def_name,
2593 jrn_def_class_deb,jrn_def_class_cred,jrn_def_type
2594 from jrn_def order by jrn_def_name");
2601 $url=$base_url.
"&sa=detail&p_jrn=".$l_line[
'jrn_def_id'];
2602 $r.=sprintf(
'<TR ledger_type="%s"><TD><A HREF="%s">%s</A></TD></TR>', $l_line[
'jrn_def_type'],
$url,
2603 h($l_line[
'jrn_def_name']).
' ('.$l_line[
'jrn_def_type'].
')');
2615 if ($this->load()==
false)
2617 throw new Exception(
_(
"Journal n'existe pas"), -1);
2619 $type=$this->jrn_def_type;
2621 $code=$this->jrn_def_code;
2625 $wSearch->set_attribute(
'ipopup',
'ipop_account');
2626 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
2627 $wSearch->set_attribute(
'no_overwrite',
'1');
2628 $wSearch->set_attribute(
'noquery',
'1');
2630 $wSearch->name=
"p_jrn_class_deb";
2632 $wSearch->value=$this->jrn_def_class_deb;
2633 $search=$wSearch->input();
2635 $wPjPref=
new IText();
2636 $wPjPref->name=
'jrn_def_pj_pref';
2637 $wPjPref->value=$this->jrn_def_pj_pref;
2638 $pj_pref=$wPjPref->input();
2642 $wPjSeq->name=
'jrn_def_pj_seq';
2647 $hidden=HtmlInput::hidden(
'p_jrn', $this->
id);
2648 $hidden.=HtmlInput::hidden(
'sa',
'detail');
2650 $hidden.=HtmlInput::hidden(
'p_jrn_deb_max_line', 10);
2651 $hidden.=HtmlInput::hidden(
'p_ech_lib',
'echeance');
2654 $min_row=
new INum(
"min_row", $this->jrn_deb_max_line);
2658 $description->style=
'class="itextarea" style="margin:0px;"';
2667 $num_op=
new ICheckBox(
'numb_operation');
2668 if ($this->jrn_def_num_op==1)
2669 $num_op->selected=
true;
2674 $f_id=$this->jrn_def_bank;
2678 $qcode_bank=$fBank->get_quick_code();
2684 $actif=
new ISelect(
"jrn_enable");
2686 [
"label"=>
_(
"Activé"),
"value"=>1],
2687 [
"label"=>
_(
"Désactivé"),
"value"=>0]
2689 $actif->selected=$this->jrn_enable;
2694 $negative=
new InputSwitch(
'negative_amount',$this->jrn_def_negative_amount);
2695 $negative_warning=
new IText(
"negative_warning",
_($this->jrn_def_negative_warning));
2696 $negative_warning->size=55;
2699 $quantity=
new InputSwitch(
'p_jrn_quantity',$this->jrn_def_quantity);
2702 $padding = new \INum (
'p_jrn_padding',$this->jrn_def_pj_padding);
2703 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
2714 $default_currency->value=$this->
db->make_array(
"select id,cr_code_iso from public.currency order by 1 ");
2716 $nb_operation=$this->
db->get_value(
"select count(*) from jrn where jr_def_id=$1",[$this->
id]);
2748 $p_jrn_deb_max_line=
$http->extract(
'p_jrn_deb_max_line');
2749 $p_jrn_name=
$http->extract(
'p_jrn_name');
2750 $p_jrn_type=
$http->extract(
'p_jrn_type');
2751 $p_jrn_quantity=
$http->extract(
'p_jrn_quantity',
'number',0);
2756 throw new Exception(
"Id invalide");
2757 if (
isNumber($p_jrn_deb_max_line)==0)
2758 throw new Exception(
_(
"Nombre de ligne incorrect"));
2759 if (trim($p_jrn_name)==
"")
2760 throw new Exception(
"Nom de journal invalide");
2761 if ($this->
db->get_value(
"select count(*) from jrn_def where jrn_def_name=$1 and jrn_Def_id<>$2",
2762 array($p_jrn_name,
$p_jrn))>0)
2763 throw new Exception(
_(
"Un journal avec ce nom existe déjà"));
2764 if ($p_jrn_type==
'FIN')
2766 $http=new \HttpInput();
2768 $bank=
$http->post(
"bank");
2769 $result=
$a->get_by_qcode(trim(strtoupper($bank)),
false);
2771 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
2773 if ($p_jrn_type==
"-1")
2775 throw new Exception(
_(
'Choix du type de journal est obligatoire'));
2778 if ( isset(
$array[
'negative_warning']) &&
2779 isset(
$array[
'negative_amount']) &&
2780 $array[
'negative_amount'] == 1
2781 && trim(
$array[
'negative_warning'])==
"") {
2783 throw new Exception(
_(
"Avertissement ne peut être vide"));
2785 if ( isset(
$array[
'negative_amount']) &&
2786 $array[
'negative_amount'] <> 0 &&
2787 $array[
'negative_amount'] <> 1 )
2789 throw new Exception(
_(
"Valeur invalide {$array['negative_amount']}"));
2792 catch (Exception
$e)
2825 $this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity===
null)?1:$this->jrn_def_quantity;
2835 $p_jrn_deb_max_line=
$http->extract(
"p_jrn_deb_max_line",
"number",-1);
2836 $min_row=
$http->extract(
"min_row");
2838 $this->jrn_def_id=
$http->extract(
'p_jrn');
2840 $this->jrn_def_ech_lib=
$http->extract(
'p_ech_lib');
2841 $this->jrn_def_max_line_deb=($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
2842 $this->jrn_def_type=
$http->extract(
'p_jrn_type');
2843 $this->jrn_def_pj_pref=
$http->extract(
'jrn_def_pj_pref');
2844 $this->jrn_deb_max_line=($min_row<1)?1:$min_row;
2845 $this->jrn_def_description=
$http->extract(
'p_description');
2846 $this->jrn_enable=
$http->extract(
'jrn_enable');
2847 $this->currency_id=0;
2848 $this->jrn_def_negative_amount=
$http->extract(
'negative_amount',
'string',0);
2849 $this->jrn_def_negative_warning=
$http->extract(
"negative_warning",
'string',
2850 _(
"Attention, ce journal doit utiliser des montants négatifs"));
2851 $this->jrn_def_quantity=
$http->extract(
'p_jrn_quantity',
'string',1);
2852 $jrn_def_pj_seq=
$http->extract(
"jrn_def_pj_seq");
2853 $this->jrn_def_pj_padding=
$http->extract(
'p_jrn_padding',
'number');
2854 switch ($this->jrn_def_type)
2857 $ACH_FICHECRED=
$http->extract(
'ACH_FICHECRED',
'array',array());
2858 $ACH_FICHEDEB=
$http->extract(
'ACH_FICHEDEB',
'array',array());
2859 $this->jrn_def_fiche_cred=(!empty($ACH_FICHECRED))?join(
',',$ACH_FICHECRED):
'';
2860 $this->jrn_def_fiche_deb=(!empty($ACH_FICHEDEB))?join(
',',$ACH_FICHEDEB):
"";
2863 $VEN_FICHECRED=
$http->extract(
'VEN_FICHECRED',
'array',array());
2864 $VEN_FICHEDEB=
$http->extract(
'VEN_FICHEDEB',
'array',array());
2865 $this->jrn_def_fiche_cred=(!empty($VEN_FICHECRED))?join(
',',$VEN_FICHECRED):
'';
2866 $this->jrn_def_fiche_deb=(!empty($VEN_FICHEDEB))?join(
',',$VEN_FICHEDEB):
"";
2870 $this->jrn_def_class_deb=
$http->extract(
'p_jrn_class_deb',
'string');
2871 $ODS_FICHEDEB=
$http->extract(
'ODS_FICHEDEB',
'array',array());
2872 $this->jrn_def_fiche_deb=(!empty($ODS_FICHEDEB))?join(
',',$ODS_FICHEDEB):
''; ;
2873 $this->jrn_def_fiche_cred=
null;
2878 $result=
$a->get_by_qcode(trim(strtoupper(
$http->extract(
'bank'))),
false);
2880 $this->jrn_def_bank=$bank;
2881 $FIN_FICHEDEB=
$http->extract(
'FIN_FICHEDEB',
'array',array());
2882 $this->jrn_def_fiche_deb=(!empty($FIN_FICHEDEB))?join(
',',$FIN_FICHEDEB):
"";
2884 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
2885 $this->jrn_def_num_op=
$http->extract(
'numb_operation',
'string',0);
2887 $nb_operation = $this->
db->get_value(
"select count(*) from jrn where jr_def_id=$1",
2888 [$this->jrn_def_id]);
2893 $this->currency_id=
$http->extract(
"defaultCurrency");
2895 $this->currency_id=$this->
db->get_value(
"select currency_id from jrn_def where jrn_def_id=$1",
2896 [$this->jrn_def_id]);
2903 if ($jrn_def_pj_seq!=0)
2905 $Res=$this->
db->alter_seq(
"s_jrn_pj".$this->jrn_def_id, $jrn_def_pj_seq);
2919 $r.=
'<div id="payment"> ';
2920 $r.=
'<h2 class="h-section"> '._(
'Paiement').
' </h2>';
2922 $mp->set_parameter(
'ledger_source', $this->
id);
2923 $r.=$mp->select($p_selected,$p_amount,
$p_date,$p_comm);
2935 $retry=
$http->post(
"sa",
"string",
"");
2937 $default_type=
$http->post(
"p_jrn_type",
"string", -1);
2938 $previous_jrn_def_pj_pref=
$http->post(
"jrn_def_pj_pref",
"string",
"");
2939 $previous_p_description=
$http->post(
"p_description",
"string",
"");
2940 $previous_p_jrn_name=
$http->post(
'p_jrn_name',
"string",
'');
2941 $previous_p_jrn_type=
$http->post(
"p_jrn_type",
"string",
"");
2944 $f_add_button->label=
_(
'Créer une nouvelle fiche');
2945 $f_add_button->tabindex=-1;
2946 $f_add_button->set_attribute(
'jrn', -1);
2947 $f_add_button->javascript=
" select_card_type({type_cat:4,elementId:'bank',p_jrn:-1});";
2953 $str_add_button=$f_add_button->input();
2957 $wSearch->set_attribute(
'ipopup',
'ipop_account');
2958 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
2959 $wSearch->set_attribute(
'no_overwrite',
'1');
2960 $wSearch->set_attribute(
'noquery',
'1');
2962 $wSearch->name=
"p_jrn_class_deb";
2965 $search=$wSearch->input();
2981 $hidden=HtmlInput::hidden(
'p_jrn', -1);
2982 $hidden.=HtmlInput::hidden(
'p_action',
'jrn');
2983 $hidden.=HtmlInput::hidden(
'sa',
'add');
2985 $hidden.=HtmlInput::hidden(
'p_jrn_deb_max_line', 10);
2986 $hidden.=HtmlInput::hidden(
'p_ech_lib',
'echeance');
2989 $name=$previous_p_jrn_name;
2992 $a_jrn=$this->
db->make_array(
"select '-1',' -- ".
_(
"choix du type de journal").
" -- ' union select jrn_type_id,jrn_desc from jrn_type");
2993 $wType->selected=
'-1';
2994 $wType->value=$a_jrn;
2995 $wType->name=
"p_jrn_type";
2996 $wType->id=
"p_jrn_type_select_id";
2997 $wType->javascript=
' onchange="show_ledger_div()"';
2998 $wType->selected=$default_type;
2999 $type=$wType->input();
3000 $rcred=$rdeb=array();
3001 $wPjPref=
new IText();
3002 $wPjPref->name=
'jrn_def_pj_pref';
3003 $wPjPref->value=$previous_jrn_def_pj_pref;
3004 $pj_pref=$wPjPref->input();
3009 $description->style=
'class="itextarea" style="margin:0px;"';
3015 $num_op=
new ICheckBox(
'numb_operation');
3016 echo dossier::hidden();
3017 echo HtmlInput::hidden(
'ac',
$http->request(
'ac'));
3027 $negative_warning=
new IText(
'negative_warning',
_(
"Attention, ce journal doit utiliser des montants négatifs"));
3028 $negative_warning->size=
"55";
3031 $padding = new \INum (
'p_jrn_padding',5);
3032 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
3076 extract(
$array, EXTR_SKIP);
3077 $this->jrn_def_id=-1;
3079 $this->jrn_def_ech_lib=$p_ech_lib;
3080 $this->jrn_def_max_line_deb=$p_jrn_deb_max_line;
3081 $this->jrn_def_type=$p_jrn_type;
3082 $this->jrn_def_pj_pref=$jrn_def_pj_pref;
3083 $this->jrn_deb_max_line=$min_row;
3084 $this->jrn_def_code=trim(substr($this->jrn_def_type, 0, 1));
3085 $this->jrn_def_code.=str_pad(
3088 $this->jrn_def_code=strtoupper($this->jrn_def_code);
3089 $this->jrn_def_description=$p_description;
3090 $this->currency_id=0;
3091 $this->jrn_def_negative_amount=$negative_amount;
3092 $this->jrn_def_negative_warning=$negative_warning;
3093 $this->jrn_enable=1;
3094 $this->jrn_def_pj_padding=$p_jrn_padding;
3095 switch ($this->jrn_def_type)
3098 $this->jrn_def_fiche_cred=(isset($ACH_FICHECRED))?join(
',',$ACH_FICHECRED):
'';
3099 $this->jrn_def_fiche_deb=(isset($ACH_FICHEDEB))?join(
',',$ACH_FICHEDEB):
"";
3102 $this->jrn_def_fiche_cred=(isset($VEN_FICHECRED))?join(
',',$VEN_FICHECRED):
'';
3103 $this->jrn_def_fiche_deb=(isset($VEN_FICHEDEB))?join(
',',$VEN_FICHEDEB):
"";
3107 $this->jrn_def_class_deb=$p_jrn_class_deb;
3108 $this->jrn_def_fiche_deb=(isset($ODS_FICHEDEB))?join(
',',$ODS_FICHEDEB):
''; ;
3109 $this->jrn_def_fiche_cred=
null;
3113 $result=
$a->get_by_qcode(trim(strtoupper($bank)),
false);
3115 $this->jrn_def_bank=$bank_id;
3116 $this->jrn_def_fiche_deb=(isset($FIN_FICHEDEB))?join(
',',$FIN_FICHEDEB):
"";
3118 throw new Exception(
_(
"Aucun compte en banque n'est donné"));
3119 $this->jrn_def_num_op=(isset($numb_operation))?1:0;
3120 $this->currency_id=$defaultCurrency;
3123 $this->jrn_def_quantity=(!isset($this->jrn_def_quantity)||$this->jrn_def_quantity==
null)?1:$this->jrn_def_quantity;
3125 $this->
id=$this->jrn_def_id;
3136 if ($this->
db->get_value(
"select count(jr_id) from jrn where jr_def_id=$1",
3137 array($this->jrn_def_id))>0)
3138 throw new Exception(
_(
"Impossible d'effacer un journal qui contient des opérations"));
3141 catch (Exception
$e)
3162 switch ($p_ledger_type)
3171 throw new Exception(
'Ledger_type invalid : '.$p_ledger_type);
3173 if ( ! in_array($sql_op ,array(
'>',
'<',
'=',
'>=',
'<='))) {
3174 throw new \Exception (
"AC3162 : invalid \$sql_op = [$sql_op]");
3177 $sql=
"select jr_id, jr_internal, jr_date, jr_comment,jr_pj_number,jr_montant,jr_ech
3179 join jrn_def on (jrn_def_id=jr_def_id)
3182 and jr_ech $sql_op to_date($1,'DD.MM.YYYY')
3183 and coalesce (jr_rapt,'xx') <> 'paid'
3201 function get_rowSimple($p_from, $p_to, $pa_ledger=[],$trunc=0,$p_limit=-1,$p_offset=-1)
3203 if ( empty($pa_ledger) ) {
3207 if ( $pa_ledger == [0] ) {
3212 $alh_generic->get_rowSimple($trunc,$p_limit,$p_offset);
3213 $data=$alh_generic->get_data();
3266 if (!
$g_user->can_read_action($p_ag_id))
3267 die(
_(
'Action non accessible'));
3271 $tiers_id=$this->
db->get_value(
'select f_id_dest from action_gestion where ag_id=$1',
3273 if ($this->
db->size()!=0)
3274 $qcode=$this->
db->get_value(
'select j_qcode from vw_poste_qcode where f_id=$1',
3279 $comment=$this->
db->get_value(
'select ag_title from action_gestion where ag_id=$1',
3282 $array[
'e_comm']=$comment;
3285 $a_item=$this->
db->get_array(
'select f_id,ad_text,ad_pu,ad_quant,ad_tva_id,ad_tva_amount,j_qcode
3288 left join vw_poste_qcode using(f_id)
3290 ag_id=$1', array($p_ag_id));
3292 $array[
'nb_item']=($this->
nb>count($a_item))?$this->
nb:count($a_item);
3293 for (
$i=0;
$i<count($a_item);
$i++)
3295 $array[
'e_march'.$i]=$a_item[
$i][
'j_qcode'];
3296 $array[
'e_march'.$i.
'_label']=$a_item[
$i][
'ad_text'];
3297 $array[
'e_march'.$i.
'_price']=$a_item[
$i][
'ad_pu'];
3298 $array[
'e_march'.$i.
'_tva_id']=$a_item[
$i][
'ad_tva_id'];
3299 $array[
'e_march'.$i.
'_tva_amount']=$a_item[
$i][
'ad_tva_amount'];
3300 $array[
'e_quant'.$i]=$a_item[
$i][
'ad_quant'];
3302 if ( $copy_description == 1) {
3303 $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
3304 FROM action_gestion_comment where ag_id=$1 order by agc_id", array($p_ag_id)
3306 if (count ($acomment) > 0)
3307 $array[
'jrn_note_input']=$acomment[0][
'agc_comment'];
3319 $lib=$this->
db->get_value(
'select pcm_lib from tmp_pcmn where pcm_val=$1',
3336 $r=(
$p_readonly==
false)?
'<div id="repo_div_id" style="height:185px;height:10rem;">':
'<div id="repo_div_id" >';
3340 $sel=HtmlInput::select_stock($this->
db,
'repo',
'W');
3343 $sel->selected=$p_repo;
3344 $r.=
"<p class=\"decale\">"._(
'Dans le dépôt').
" : ";
3349 $r.=
'<span class="notice">'.
'Stock non utilisé'.
'</span>';
3363 $button=HtmlInput::button_anchor(
_(
"Nouvelle opération"),
3364 'do.php?'.
$url,
"",
"",
"smallbutton");
3365 return '<p>'.$button.
'</p>';
3374 echo
'<FORM METHOD="POST">';
3375 echo HtmlInput::post_to_hidden(
3376 array(
"gDossier",
"ac",
"p_jrn",
"e_client",
"nb_item",
"desc",
"e_comm")
3378 echo HtmlInput::hidden(
"correct",
"copy");
3381 $nb=
$http->post(
"nb_item",
"number", 0);
3382 echo HtmlInput::post_to_hidden([
'p_currency_rate',
'p_currency_code']);
3383 echo HtmlInput::post_to_hidden([
'other_tax',
'other_tax_amount']);
3386 echo HtmlInput::post_to_hidden(
3389 "e_march".
$i.
"_price",
3390 "e_march".$i.
"_quant",
3391 "e_march".$i.
"_label",
3392 "e_march".$i.
"_tva_id",
3393 "e_march".$i.
"_tva_amount",
3402 echo HtmlInput::submit(
"copy_operation",
_(
"Opération identique"));
3414 $js_script=
"this.filter='{$p_filter}';this.elementId='{$p_id_update}';this.jrn=\$('p_jrn').value; select_card_type(this);";
3416 return $str_add_button;
3423 return $this->
db->get_value(
"select jrn_enable from jrn_def where jrn_def_id=$1",[$this->
id]);
3430 return $this->jrn_def_quantity;
3438 $this->jrn_def_quantity=$p_value;
3449 if ( $p_jrn_type ==
'ACH')
3451 $sql=
"select count(*) from jrnx join quant_purchase using (j_id) where j_grpt=$1";
3452 }
elseif ($p_jrn_type==
'VEN')
3454 $sql=
"select count(*) from jrnx join quant_sold using (j_id) where j_grpt=$1";
3455 }
elseif ($p_jrn_type==
'FIN')
3457 $sql=
"select count(*) from jrn join quant_fin using (jr_id) where jr_grpt_id=$1";
3459 }
elseif ($p_jrn_type==
'ODS')
return 0;
3462 throw new Exception(
_(
'Journal incorrect'),1000);
3467 if (
$count > 0)
return TRUE;
3487 $select->javascript=sprintf(
'onchange="LedgerCurrencyUpdateMisc(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
3488 '$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
3489 Dossier::id(),
$select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
3494 $select->javascript=sprintf(
'onchange="LedgerCurrencyUpdate(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\');'.
3495 '$(\'update_p_currency_rate\').innerHTML=$(\'p_currency_rate\').value;"',
3496 Dossier::id(),
$select->name, $p_currency_code, $p_currency_rate, $p_eur_amount);
3500 throw new Exception(
_(
"Journal type non déterminé"));
3511 if ( $cr->get_id() < 0 ) {
3512 throw new Exception(
"ACL.3214".
_(
"Taux invalide"));
3524 if ($this->
id == 0) {
3525 throw new Exception(
_(
"Journal invalide"), 1);
3528 if ( $p_amount > 0 &&
$ledger->getp(
"jrn_def_negative_amount")==1){
3529 return _(
$ledger->getp(
"jrn_def_negative_warning"));
3535 require NOALYSS_TEMPLATE.
"/acc_ledger-input_extra_info.php";
3545 if ($this->jr_id == 0 || empty ($s_related_action)) {
return false; }
3549 $acc_operation->insert_related_action($s_related_action);
3565 $amount->value=
$http->request(
"other_tax_amount",
"number",0);
3567 $amount->javascript=
'onchange="format_number(this,2);refresh_ledger();"';
3569 $row=$this->
cn->get_row(
"select ac_id,ac_label,ac_rate from acc_other_tax where $1 = any (ajrn_def_id)",
3574onchange=
'if (! this.checked) { $("other_tax_amount").value=0;}compute_all_ledger();'
3585 $out.=
"<h4>"._(
"Total opération").
3586 "<span class=\"mx-4\" id='total_operation_other_tax'>".
3598 $row=$this->
cn->get_row(
"select ac_id,ac_label,ac_rate from acc_other_tax where ac_id=$1",
3599 [$p_additional_tax]);
3602 $p_amount=
h($p_amount);
3604<div
id=
"additional_tax">
3619 $cnt=$this->
db->get_value(
'select count(*)
3621 where array_position(ajrn_def_id,$1) is not null',[$this->
id]);
3622 if ($cnt == 0 )
return false;
3636 if (empty(
$p_array[
'e_pj']))
return true;
3637 if (empty(
$p_array[
'e_pj_suggest']))
return true;
3652 return span (
_(
"Attention ! Numéro de Pièce non automatique mais forcée"),
'class="warning"');
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='')
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
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
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,...")
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.
$currency_id
!< default number of rows by default 10
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
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...
$nb
!< type of the ledger ACH ODS FIN VEN or GL
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...
$is_loaded
!< is_loaded true the ledger definition is loaded or false, it is not
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.
$row
!< database connextion
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
$ledger_type
!< row of the ledger
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.
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
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_all($ret)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
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...
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.
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