20 require_once NOALYSS_INCLUDE.
'/lib/class_iselect.php';
21 require_once NOALYSS_INCLUDE.
'/lib/class_icard.php';
22 require_once NOALYSS_INCLUDE.
'/lib/class_ispan.php';
23 require_once NOALYSS_INCLUDE.
'/lib/class_ihidden.php';
24 require_once NOALYSS_INCLUDE.
'/lib/class_idate.php';
25 require_once NOALYSS_INCLUDE.
'/lib/class_itext.php';
26 require_once NOALYSS_INCLUDE.
'/lib/class_icheckbox.php';
27 require_once NOALYSS_INCLUDE.
'/lib/class_iperiod.php';
28 require_once NOALYSS_INCLUDE.
'/class/class_fiche.php';
29 require_once NOALYSS_INCLUDE.
'/class/class_user.php';
30 require_once NOALYSS_INCLUDE.
'/class/class_dossier.php';
31 require_once NOALYSS_INCLUDE.
'/class/class_anc_operation.php';
32 require_once NOALYSS_INCLUDE.
'/class/class_acc_operation.php';
33 require_once NOALYSS_INCLUDE.
'/class/class_acc_account_ledger.php';
34 require_once NOALYSS_INCLUDE.
'/class/class_pre_op_advanced.php';
35 require_once NOALYSS_INCLUDE.
'/class/class_acc_reconciliation.php';
36 require_once NOALYSS_INCLUDE.
'/class/class_periode.php';
37 require_once NOALYSS_INCLUDE.
'/class/class_gestion_purchase.php';
38 require_once NOALYSS_INCLUDE.
'/class/class_gestion_sold.php';
39 require_once NOALYSS_INCLUDE.
'/class/class_acc_account.php';
40 require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
41 require_once NOALYSS_INCLUDE.
'/lib/class_inum.php';
42 require_once NOALYSS_INCLUDE.
'/class/class_lettering.php';
43 require_once NOALYSS_INCLUDE.
'/lib/class_sort_table.php';
44 require_once NOALYSS_INCLUDE.
'/database/class_jrn_def_sql.php';
45 require_once NOALYSS_INCLUDE.
'/class/class_acc_payment.php';
83 throw new Exception(_(
"Paramètre invalide"));
86 if ($this->
db->exist_sequence(
"s_jrn_pj" . $this->id))
88 $ret = $this->
db->get_array(
"select last_value,is_called from s_jrn_pj" . $this->
id);
93 if (
$ret[0][
'is_called'] ==
'f')
98 $this->
db->create_sequence(
"s_jrn_pj" . $this->
id);
111 $this->
name = _(
" Tous les journaux");
116 $Res = $this->
db->exec_sql(
"select jrn_def_type from " .
117 " jrn_def where jrn_def_id=" .
124 return $ret[
'jrn_def_type'];
146 $grpt_id = $this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1', array($this->
jr_id));
147 if ($this->
db->count() == 0)
149 $this->
db->exec_sql(
'delete from jrnx where j_grpt=$1', array($grpt_id));
150 $this->
db->exec_sql(
'delete from jrn where jr_id=$1', array($this->
jr_id));
159 $str =
'<p class="notice"> ' . $p_warning;
160 $str.=
"<ol class=\"notice\">";
161 for ($i = 0; $i < count($pa_msg); $i++)
163 $str.=
"<li>" . $pa_msg[$i] .
"</li>";
194 if (!isset($this->
jr_id) || $this->
jr_id ==
'')
195 throw new Exception(_(
"this->jr_id is not set ou opération inconnue"));
199 throw new Exception(_(
'Date invalide') .
$p_date);
203 $grp_new = $this->
db->get_next_seq(
's_grpt');
204 $seq = $this->
db->get_next_seq(
"s_jrn");
206 $this->jr_grpt_id = $this->
db->get_value(
'select jr_grpt_id from jrn where jr_id=$1', array($this->
jr_id));
207 if ($this->
db->count() == 0)
208 throw new Exception(_(
"Cette opération n'existe pas"));
209 $this->jr_internal = $this->
db->get_value(
'select jr_internal from jrn where jr_id=$1', array($this->
jr_id));
210 if ($this->
db->count() == 0 ||
trim($this->jr_internal) ==
'')
211 throw new Exception(_(
"Cette opération n'existe pas"));
218 if (
$per->is_open() == 0)
219 throw new Exception(_(
'PERIODE FERMEE'));
227 $sql =
"update jrn set jr_comment='extourne : '||jr_comment where jr_id=$1";
232 throw new Exception(__FILE__ . __LINE__ .
"sql a echoue [ $sql ]");
237 $a_jid = $this->
db->get_array(
"select j_id,j_debit from jrnx where j_grpt=$1", array($this->jr_grpt_id));
238 for (
$l = 0;
$l < count($a_jid);
$l++)
240 $row = $a_jid[
$l][
'j_id'];
242 $sql =
"insert into jrnx (
243 j_date,j_montant,j_poste,j_grpt,
244 j_jrn_def,j_debit,j_text,j_internal,j_tech_user,j_tech_per,j_qcode
245 ) select to_date($1,'DD.MM.YYYY'),j_montant,j_poste,$2,
246 j_jrn_def,not (j_debit),j_text,$3,$4,$5,
250 where j_id=$6 returning j_id";
254 throw (
new Exception(__FILE__ . __LINE__ .
"SQL ERROR [ $sql ]"));
255 $aj_id = $this->
db->fetch(0);
256 $j_id = $aj_id[
'j_id'];
263 $Res = $this->
db->exec_sql(
"INSERT INTO quant_sold(
264 qs_internal, qs_fiche, qs_quantite, qs_price, qs_vat,
265 qs_vat_code, qs_client, qs_valid, j_id)
266 SELECT $1, qs_fiche, qs_quantite*(-1), qs_price*(-1), qs_vat*(-1),
267 qs_vat_code, qs_client, qs_valid, $2
268 FROM quant_sold where j_id=$3", array($p_internal, $j_id,
$row));
271 throw new Exception(__FILE__ . __LINE__ .
"sql a echoue [ $sql ]");
272 $Res = $this->
db->exec_sql(
"INSERT INTO quant_purchase(
273 qp_internal, j_id, qp_fiche, qp_quantite, qp_price, qp_vat,
274 qp_vat_code, qp_nd_amount, qp_nd_tva, qp_nd_tva_recup, qp_supplier,
275 qp_valid, qp_dep_priv)
276 SELECT $1, $2, qp_fiche, qp_quantite*(-1), qp_price*(-1), qp_vat*(-1),
277 qp_vat_code, qp_nd_amount*(-1), qp_nd_tva*(-1), qp_nd_tva_recup*(-1), qp_supplier,
278 qp_valid, qp_dep_priv*(-1)
279 FROM quant_purchase where j_id=$3", array($p_internal, $j_id,
$row));
282 throw new Exception(__FILE__ . __LINE__ .
"SQL ERROR [ $sql ]");
284 $sql =
"insert into jrn (
292 ,jr_tech_per, jr_valid
294 select $1,jr_def_id,jr_montant,jr_comment,
295 to_date($2,'DD.MM.YYYY'),$3,$4,
303 throw (
new Exception(__FILE__ . __LINE__ .
"SQL ERROR [ $sql ]"));
305 $Res = $this->
db->exec_sql(
" INSERT INTO quant_fin(
306 qf_bank, qf_other, qf_amount,jr_id)
307 SELECT qf_bank, qf_other, qf_amount*(-1),$1
308 FROM quant_fin where jr_id=$2", array(
$seq, $this->
jr_id));
310 throw (
new Exception(__FILE__ . __LINE__ .
"SQL ERROR[ $sql ]"));
315 $rec->set_jr_id(
$seq);
316 $rec->insert($this->
jr_id);
321 throw (
new Exception(__FILE__ . __LINE__ .
"SQL ERROR [ $sql ]"));
328 $sql =
"delete from stock_goods where sg_id = any ( select sg_id
329 from stock_goods natural join jrnx where j_grpt=" . $this->jr_grpt_id .
")";
332 throw (
new Exception(__FILE__ . __LINE__ .
"SQL ERROR [ $sql ]"));
337 $this->
db->rollback();
351 $this->
name = _(
"Grand Livre");
355 $Res = $this->
db->exec_sql(
"select jrn_def_name from " .
356 " jrn_def where jrn_def_id=$1", array($this->
id));
362 return $ret[
'jrn_def_name'];
377 function get_row($p_from, $p_to, $p_limit = -1, $p_offset = -1)
382 $cond_limite = ($p_limit != -1) ?
" limit " . $p_limit .
" offset " . $p_offset :
"";
388 $Res = $this->
db->exec_sql(
"select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
390 case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
391 case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
392 j_debit as debit,j_poste as poste,j_qcode,jr_montant , " .
393 "case when j_text='' or j_text is null then pcm_lib else j_text end as description,j_grpt as grp,
394 jr_comment||' ('||jr_internal||')' as jr_comment,
397 jr_rapt as oc, j_tech_per as periode
398 from jrnx left join jrn on " .
399 "jr_grpt_id=j_grpt " .
400 " left join tmp_pcmn on pcm_val=j_poste " .
401 " where j_jrn_def=" . $this->
id .
402 " and " .
$periode .
" order by j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit desc " .
407 $Res = $this->
db->exec_sql(
"select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
409 case j_debit when 't' then j_montant::text else ' ' end as deb_montant,
410 case j_debit when 'f' then j_montant::text else ' ' end as cred_montant,
411 j_debit as debit,j_poste as poste,j_qcode," .
412 "case when j_text='' or j_text is null then pcm_lib else j_text end as description,j_grpt as grp,
413 jr_comment||' ('||jr_internal||')' as jr_comment,
417 jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on " .
418 "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste
419 join jrn_def on (jr_def_id=jrn_def_id)
421 $g_user->get_ledger_sql() .
" and " .
422 " " .
$periode .
" order by j_date::date,substring(jr_pj_number,'[0-9]+$') asc,j_grpt,j_debit desc " .
435 for ($i = 0; $i <
$Max; $i++)
439 $mont_deb = (
$line[
'deb_montant'] != 0) ? sprintf(
"% 8.2f",
$line[
'deb_montant']) :
"";
440 $mont_cred = (
$line[
'cred_montant'] != 0) ? sprintf(
"% 8.2f",
$line[
'cred_montant']) :
"";
441 $jr_montant = (
$line[
'jr_montant'] != 0) ? sprintf(
"% 8.2f",
$line[
'jr_montant']) :
"";
444 $tot_op =
$line[
'jr_montant'];
449 if (
$fiche->get_by_qcode(
$line[
'j_qcode'],
false) == 0)
454 if ($case !=
$line[
'grp'])
456 $case =
$line[
'grp'];
458 if ($this->
type ==
'FIN')
460 $amount = $this->
db->get_value(
'select qf_amount from quant_fin where jr_id=$1', array(
$line[
'jr_id']));
462 if ($this->
db->count() == 0)
463 $tot_op = $jr_montant;
470 'jr_id' =>
$line[
'jr_id'],
471 'int_j_id' =>
$line[
'int_j_id'],
472 'j_id' =>
$line[
'j_id'],
473 'j_date' =>
$line[
'j_date'],
474 'internal' =>
$line[
'jr_internal'],
476 'cred_montant' =>
' ',
477 'description' =>
'<b><i>' .
h(
$line[
'jr_comment']) .
' [' . $tot_op .
'] </i></b>',
478 'poste' =>
$line[
'oc'],
479 'j_qcode' =>
$line[
'j_qcode'],
480 'periode' =>
$line[
'periode'],
481 'jr_pj_number' =>
$line [
'jr_pj_number']);
485 'int_j_id' =>
$line[
'int_j_id'],
489 'deb_montant' => $mont_deb,
490 'cred_montant' => $mont_cred,
491 'description' =>
$line[
'description'],
492 'poste' =>
$line[
'poste'],
493 'j_qcode' =>
$line[
'j_qcode'],
494 'periode' =>
$line[
'periode'],
501 'jr_id' =>
$line[
'jr_id'],
502 'int_j_id' =>
$line[
'int_j_id'],
506 'deb_montant' => $mont_deb,
507 'cred_montant' => $mont_cred,
508 'description' =>
$line[
'description'],
509 'poste' =>
$line[
'poste'],
510 'j_qcode' =>
$line[
'j_qcode'],
511 'periode' =>
$line[
'periode'],
512 'jr_pj_number' =>
'');
531 function get_rowSimple($p_from, $p_to, $trunc = 0, $p_limit = -1, $p_offset = -1)
536 $jrn = ($this->
id == 0 ) ?
"and " . $g_user->get_ledger_sql() :
"and jrn_def_id = " .
$this->id;
540 $cond_limite = ($p_limit != -1) ?
" limit " . $p_limit .
" offset " . $p_offset :
"";
543 SELECT jrn.jr_id as jr_id ,
545 jrn.jr_def_id as jr_def_id,
546 jrn.jr_montant as montant,
547 substr(jrn.jr_comment,1,35) as comment,
548 to_char(jrn.jr_date,'DD-MM-YYYY') as date,
549 to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
552 jrn.jr_grpt_id as grpt_id,
553 jrn.jr_pj_name as pj,
556 FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
557 WHERE $periode $jrn order by jr_date,substring(jrn.jr_pj_number,'[0-9]+$')::numeric asc $cond_limite";
569 $a_ParmCode = $this->
db->get_array(
'select p_code,p_value from parm_code');
570 $a_TVA = $this->
db->get_array(
'select tva_id,tva_label,tva_poste
571 from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id ');
572 for ($i = 0; $i <
$Max; $i++)
576 if (
$array[$i][
'dep_priv'] != 0.0)
578 $array[$i][
'comment'].=
"(priv. " .
$array[$i][
'dep_priv'] .
")";
599 $pj_pref =
$prop[
"jrn_def_pj_pref"];
639 $limit =
" LIMIT ".MAX_RECONCILE;
658 return array(0, _(
"Aucun enregistrement trouvé"));
660 $r.=
'<table class="result">';
664 $r.=
"<th>"._(
"Selection").
"</th>";
665 $r.=
"<th>"._(
"Internal").
"</th>";
667 if ($this->
type ==
'ALL')
669 $r.=
th(_(
'Journal'));
672 $r.=
'<th>'._(
"Date").
'</th>';
673 $r.=
'<th>'._(
"Pièce").
'</td>';
675 $r.=
'<th>'._(
"Description").
'</th>';
676 $r.=
th(_(
'Notes'),
' ');
677 $r.=
'<th>'._(
"Montant").
'</th>';
678 $r.=
"<th>" . _(
'Concerne') .
"</th>";
684 for ($i = 0; $i <
$Max; $i++)
691 $tr =
'<TR class="odd">';
693 $tr =
'<TR class="even">';
698 $r.=
'<td><INPUT TYPE="CHECKBOX" name="jr_concerned' .
$row[
'jr_id'] .
'" ID="jr_concerned' .
$row[
'jr_id'] .
'" value="'.$row[
'quick_code'].
'"> </td>';
705 $href = basename($_SERVER[
'PHP_SELF']);
708 $r.=sprintf(
'<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
$row[
'jr_id'],
$gDossier,
$row[
'jr_internal']);
710 if ($this->
type ==
'ALL')
723 $other = (
$row[
'quick_code'] !=
'') ?
'[' .
$row[
'quick_code'] .
'] ' .
$row[
'name'] .
' ' .
$row[
'first_name'] :
'';
727 $tmp_jr_comment =
h(
$row[
'jr_comment']);
730 $r.=
td(
h(
$row[
'n_text']),
' style="font-size:0.87em"');
737 if (
$row[
'jrn_def_type'] ==
'FIN')
739 $positive = $this->
db->get_value(
"select qf_amount from quant_fin where jr_id=$1", array(
$row[
'jr_id']));
740 if ($this->
db->count() != 0)
741 $positive = ($positive < 0) ? 1 : 0;
743 $r.=
"<TD align=\"right\">";
745 $r.=( $positive != 0 ) ?
"<font color=\"red\"> - " .
nbm(
$row[
'jr_montant']) .
"</font>" :
nbm(
$row[
'jr_montant']);
752 $rec->set_jr_id(
$row[
'jr_id']);
758 foreach (
$a as
$key => $element)
762 $l_amount = $this->
db->get_value(
"select jr_montant from jrn " .
763 " where jr_id=$1",array($element));
764 $r.=
"<A class=\"detail\" HREF=\"javascript:modifyOperation('" . $element .
"'," .
$gDossier .
")\" > " .
$operation->get_internal() .
"[" .
nbm($l_amount) .
"]</A>";
769 if (
$row[
'jr_valid'] ==
'f')
771 $r.=
"<TD>"._(
"Opération annulée").
"</TD>";
818 $amount_unpaid = 0.0;
819 $limit = ($_SESSION[
'g_pagesize'] != -1) ?
" LIMIT " . $_SESSION[
'g_pagesize'] :
"";
821 $order =
" order by jr_date_order asc,jr_internal asc";
825 $table->add(_(
"Date"),
$url,
'order by jr_date asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
'order by jr_date desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
"da",
"dd");
826 $table->add(_(
'Echeance'),
$url,
" order by jr_ech asc",
" order by jr_ech desc",
'ea',
'ed');
827 $table->add(_(
'Paiement'),
$url,
" order by jr_date_paid asc",
" order by jr_date_paid desc",
'eap',
'edp');
828 $table->add(_(
'Pièce'),
$url,
' order by substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
' order by substring(jr_pj_number,\'[0-9]+$\')::numeric desc ',
"pja",
"pjd");
829 $table->add(_(
'Tiers'),
$url,
" order by name asc",
" order by name desc",
'na',
'nd');
830 $table->add(_(
'Montant'),
$url,
" order by jr_montant asc",
" order by jr_montant desc",
"ma",
"md");
831 $table->add(_(
"Description"),
$url,
"order by jr_comment asc",
"order by jr_comment desc",
"ca",
"cd");
852 return array(0, _(
"Aucun enregistrement trouvé"));
854 $r.=
'<table class="result">';
858 $r.=
"<th>"._(
"n° interne").
"</th>";
859 if ($this->
type ==
'ALL')
863 $r.=
'<th>' .
$table->get_header(0) .
'</th>';
864 if ($p_paid != 0 )
$r.=
'<th>' .
$table->get_header(1) .
'</td>';
865 if ($p_paid != 0 )
$r.=
'<th>' .
$table->get_header(2) .
'</th>';
866 $r.=
'<th>' .
$table->get_header(3) .
'</th>';
867 $r.=
'<th>' .
$table->get_header(4) .
'</th>';
868 $r.=
'<th>' .
$table->get_header(6) .
'</th>';
869 $r.=
th(
'Notes',
' style="width:15%"');
870 $r.=
'<th>' .
$table->get_header(5) .
'</th>';
874 $r.=
"<th> " . _(
'Payé') .
"</th>";
876 $r.=
"<th>" . _(
'Concerne') .
"</th>";
877 $r.=
"<th>" . _(
'Document') .
"</th>";
882 for ($i = 0; $i <
$Max; $i++)
889 $tr =
'<TR class="odd">';
891 $tr =
'<TR class="even">';
899 $href = basename($_SERVER[
'PHP_SELF']);
902 $r.=sprintf(
'<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
$row[
'jr_id'],
$gDossier,
$row[
'jr_internal']);
904 if ($this->
type ==
'ALL')
917 $r.=
$row[
'str_jr_date_paid'];
927 $other = (
$row[
'quick_code'] !=
'') ?
'[' .
$row[
'quick_code'] .
'] ' .
$row[
'name'] .
' ' .
$row[
'first_name'] :
'';
931 $tmp_jr_comment =
h(
$row[
'jr_comment']);
934 $r.=
td(
h(
$row[
'n_text']),
' style="font-size:0.87em%"');
941 if (
$row[
'jrn_def_type'] ==
'FIN')
943 $positive = $this->
db->get_value(
"select qf_amount from quant_fin where jr_id=$1", array(
$row[
'jr_id']));
944 if ($this->
db->count() != 0)
945 $positive = ($positive < 0) ? 1 : 0;
947 $r.=
"<TD align=\"right\">";
948 $t_amount=
$row[
'jr_montant'];
949 if (
$row[
'total_invoice'] != null &&
$row[
'total_invoice'] !=
$row[
'jr_montant'])
950 $t_amount=
$row[
'total_invoice'];
951 $tot = ($positive != 0) ? bcsub(
$tot , $t_amount ): bcadd(
$tot , $t_amount);
953 if (
$row [
'jrn_def_type']==
'FIN')
955 $r.=( $positive != 0 ) ?
"<font color=\"red\"> - " .
nbm($t_amount) .
"</font>" :
nbm($t_amount);
959 $r.=( $t_amount < 0 ) ?
"<font color=\"red\"> " .
nbm($t_amount) .
"</font>" :
nbm($t_amount);
968 $w->name =
"rd_paid" .
$row[
'jr_id'];
969 $w->selected = (
$row[
'jr_rapt'] ==
'paid') ?
true :
false;
971 $w->readonly = ( $p_paid == 2) ?
true :
false;
973 $h->name =
"set_jr_id" .
$row[
'jr_id'];
974 $r.=
'<TD>' .
$w->input() . $h->input() .
'</TD>';
975 if (
$row[
'jr_rapt'] ==
'paid')
976 $amount_paid=bcadd($amount_paid,$t_amount);
978 $amount_unpaid=bcadd($amount_unpaid,$t_amount);
983 $rec->set_jr_id(
$row[
'jr_id']);
989 foreach (
$a as
$key => $element)
993 $l_amount = $this->
db->get_value(
"select jr_montant from jrn " .
994 " where jr_id=$1",array($element));
995 $r.=
"<A class=\"detail\" HREF=\"javascript:modifyOperation('" . $element .
"'," .
$gDossier .
")\" > " .
$operation->get_internal() .
"[" .
nbm($l_amount) .
"]</A>";
1000 if (
$row[
'jr_valid'] ==
'f')
1002 $r.=
"<TD>"._(
"Opération annulée").
"</TD>";
1009 if (
$row[
'jr_pj_name'] !=
"")
1011 $r.=
'<td>'.HtmlInput::show_receipt_document(
$row[
'jr_id']).
'</td>';
1019 $amount_paid = round($amount_paid, 4);
1020 $amount_unpaid = round($amount_unpaid, 4);
1023 $r.=
'<TD COLSPAN="5">Total</TD>';
1024 $r.=
'<TD ALIGN="RIGHT">' .
nbm(
$tot) .
"</TD>";
1029 $r.=
'<TD COLSPAN="5">'._(
"Payé").
'</TD>';
1030 $r.=
'<TD ALIGN="RIGHT">' .
nbm($amount_paid) .
"</TD>";
1033 $r.=
'<TD COLSPAN="5">'._(
"Non payé").
'</TD>';
1034 $r.=
'<TD ALIGN="RIGHT">' .
nbm($amount_unpaid) .
"</TD>";
1076 $a_TVA = $this->
db->get_array(
'select tva_id,tva_label,tva_poste
1077 from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id');
1079 if ($a_ParmCode == null)
1082 $a_ParmCode = $this->
db->get_array(
'select p_code,p_value from parm_code');
1097 $sql =
"select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where " .
1099 $Res2 = $this->
db->exec_sql(
$sql);
1104 foreach ($data_jrnx as
$code)
1110 if (strlen(
trim($code[
'j_qcode'])) != 0 &&
$poste->isTva() == 0)
1113 $fiche->get_by_qcode(
trim($code[
'j_qcode']),
false);
1114 $fiche_def_id =
$fiche->get_fiche_def_ref_id();
1120 $p_array[
'TVAC'] = $code[
'j_montant'];
1126 $p_array[
'reversed'] =
true;
1127 $p_array[
'TVAC']*=-1;
1131 $p_array[
'reversed'] =
true;
1132 $p_array[
'TVAC']*=-1;
1136 $p_array[
'reversed'] =
true;
1137 $p_array[
'TVAC']*=-1;
1149 $p_array[
'TVAC'] = $code[
'j_montant'];
1153 if ($p_jrn_type ==
'ACH' && $code[
'j_debit'] ==
't')
1155 $p_array[
'reversed'] =
true;
1156 $p_array[
'TVAC']*=-1;
1158 if ($p_jrn_type ==
'VEN' && $code[
'j_debit'] ==
'f')
1160 $p_array[
'reversed'] =
true;
1161 $p_array[
'TVAC']*=-1;
1167 foreach ($a_TVA as $line_tva)
1169 list($tva_deb, $tva_cred) = explode(
',', $line_tva[
'tva_poste']);
1170 if ($code[
'j_poste'] == $tva_deb ||
1171 $code[
'j_poste'] == $tva_cred)
1175 if ($p_jrn_type ==
'ACH' && $code[
'j_debit'] ==
'f')
1177 $code[
'j_montant'] = -1 * $code[
'j_montant'];
1179 if ($p_jrn_type ==
'VEN' && $code[
'j_debit'] ==
't')
1181 $code[
'j_montant'] = -1 * $code[
'j_montant'];
1184 $p_array[
'AMOUNT_TVA']+=$code[
'j_montant'];
1186 $p_array[
'TVA'][$c] = array($idx_tva, array($line_tva[
'tva_id'], $line_tva[
'tva_label'], $code[
'j_montant']));
1196 if (
$p_array[
'jrn_def_type'] ==
'ACH')
1198 $purchase =
new Gestion_Purchase($this->
db);
1199 $purchase->search_by_jid($code[
'j_id']);
1201 $dep_priv+=$purchase->qp_dep_priv;
1204 $p_array[
'tva_dna']=bcadd(
$p_array[
'tva_dna'],bcadd($purchase->qp_nd_tva,$purchase->qp_nd_tva_recup));
1207 if (
$p_array[
'jrn_def_type'] ==
'VEN') {
1209 $sold->search_by_jid($code[
'j_id']);
1219 $a_tva_amount = array();
1221 foreach (
$p_array[
'TVA'] as $linetva)
1223 foreach ($a_TVA as $tva)
1225 if ($tva[
'tva_id'] == $linetva[1][0])
1227 $a = $tva[
'tva_id'];
1228 $a_tva_amount[
$a] = $linetva[1][2];
1232 foreach ($a_TVA as $line_tva)
1234 $a = $line_tva[
'tva_id'];
1235 if (isset($a_tva_amount[
$a]))
1237 $tmp = sprintf(
"% 10.2f", $a_tva_amount[$a]);
1241 $r.=sprintf(
"% 10.2f", 0);
1261 $Res = $this->
db->exec_sql(
"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
1262 jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code,
1263 jrn_def_fiche_deb,jrn_def_fiche_cred,jrn_def_pj_pref
1265 where jrn_def_id=$1", array($this->
id));
1269 echo
'<DIV="redcontent"><H2 class="error">' . _(
'Parametres journaux non trouves') .
'</H2> </DIV>';
1284 $sql_cred =
'jrn_deb_max_line';
1285 $sql =
"select jrn_deb_max_line as value from jrn_def where jrn_def_id=$1";
1286 $r = $this->
db->exec_sql(
$sql, array($this->
id));
1288 if (
sizeof(
$Res) == 0)
1290 return $Res[0][
'value'];
1308 $sql =
'select j_montant as montant,j_debit as deb from jrnx where '
1318 if ($line[
'deb'] ==
't')
1319 $deb+=$line[
'montant'];
1321 $cred+=$line[
'montant'];
1347 $ret[
$idx][
'value'] = $value[
'jrn_def_id'];
1348 $ret[
$idx][
'label'] =
h($value[
'jrn_def_name']);
1372 $sql =
"select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred " .
1373 " from jrn_def where " .
1374 " jrn_def_id = $1 ";
1376 $r = $this->
db->exec_sql(
$sql, array($this->
id));
1394 $sql =
"select jrn_def_class_deb " .
1395 " from jrn_def where " .
1398 $r = $this->
db->exec_sql(
$sql, array($this->
id));
1423 return 'Aucun résultat';
1429 $lPeriode->p_id = $period;
1433 $lPeriode->find_periode($e_date);
1442 $ret.=$this->
display_warning(
$msg, _(
"Attention : il vaut mieux utiliser les fiches que les postes comptables"));
1445 $ret.=
"<tr><td>" . _(
'Date') .
" : </td><td>$e_date</td></tr>";
1449 $ret.=
"<tr><td>" . _(
'Libellé') .
" </td><td>" .
h(
$desc) .
"</td></tr>";
1450 $ret.=
"<tr><td>" . _(
'PJ Num') .
" </td><td>" .
h($e_pj) .
"</td></tr>";
1452 $ret.=
"<table class=\"result\">";
1454 $ret.=
"<th>" . _(
'Quick Code ou ');
1455 $ret.=_(
"Poste") .
" </th>";
1456 $ret.=
"<th style=\"text-align:left\"> " . _(
"Libellé") .
" </th>";
1457 $ret.=
"<th style=\"text-align:right\">" . _(
"Débit") .
"</th>";
1458 $ret.=
"<th style=\"text-align:right\">" . _(
"Crédit") .
"</th>";
1460 if ($g_parameter->MY_ANALYTIC !=
'nu')
1463 $a_anc =
$anc->get_list();
1466 $ret.=
'<th colspan="' . $x .
'" style="width:auto;text-align:center" >' . _(
'Compt. Analytique') .
'</th>';
1478 $mt = microtime(
true);
1489 $ret.=dossier::hidden();
1491 for ($i = 0; $i < $nb_item; $i++)
1495 if (!isset(${
'qc_' . $i}))
1497 if (!isset(${
'poste' . $i}))
1498 ${
'poste' . $i} =
'';
1499 if (!isset(${
'amount' . $i}))
1500 ${
'amount' . $i} =
'';
1502 $class=($i%2==0)?
' class="even" ':
' class="odd" ';
1503 $ret.=
"<tr $class> ";
1504 if (
trim(${
'qc_' . $i}) !=
"")
1507 $oqc->get_by_qcode(${
'qc_' . $i},
false);
1510 ${
'qc_' . $i} .
' - ' .
1515 if (
trim(${
'qc_' . $i}) ==
"" &&
trim(${
'poste' . $i}) !=
"")
1518 $strPoste = $oposte->id;
1519 $ret.=
"<td>" .
h(${
"poste" . $i} .
" - " .
1524 if (
trim(${
'qc_' . $i}) ==
"" &&
trim(${
'poste' . $i}) ==
"")
1529 if (isset(${
"ck$i"}))
1532 $total_deb = bcadd($total_deb, ${
'amount' . $i});
1537 $total_cred = bcadd($total_cred, ${
"amount" . $i});
1544 if ($g_parameter->MY_ANALYTIC !=
'nu')
1546 if (preg_match(
"/^[6,7]+/", $strPoste) == 1)
1550 $null = ($g_parameter->MY_ANALYTIC ==
'op') ? 1 : 0;
1555 $ret.=
'<td style="text-align:center">';
1567 $ret.=
tr(
td(
'') .
td(_(
'Totaux')) .
td($total_deb,
'class="num"') .
td($total_cred,
'class="num"'),
'class="highlight"');
1569 if ($g_parameter->MY_ANALYTIC !=
'nu' &&
$p_readonly ==
false)
1570 $ret.=
'<input type="button" class="button" value="' . _(
'verifie Imputation Analytique') .
'" onClick="verify_ca(\'\');">';
1575 $row=$this->
db->get_value(
"select jrn_deb_max_line from jrn_def where jrn_def_id=$1",array($this->
id));
1596 if ($g_parameter->MY_PJ_SUGGEST ==
'Y')
1598 $add_js =
"update_pj();";
1600 if ($g_parameter->MY_DATE_SUGGEST==
'Y')
1602 $add_js.=
'get_last_date();';
1604 $add_js.=
'update_row("quick_item");';
1606 if ($g_user->check_action(
FICADD) == 1)
1609 $f_add_button =
new IButton(
'add_card');
1610 $f_add_button->label = _(
'Créer une nouvelle fiche');
1611 $f_add_button->set_attribute(
'ipopup',
'ipop_newcard');
1612 $f_add_button->set_attribute(
'jrn', $this->
id);
1613 $f_add_button->javascript =
" this.jrn=\$('p_jrn').value;select_card_type(this);";
1614 $f_add_button->input();
1618 throw new Exception(_(
'Pas de journal disponible'));
1619 $wLedger->javascript =
"onChange='update_name();update_predef(\"ods\",\"t\",\"".$_REQUEST[
'ac'].
"\");$add_js'";
1631 $e_date = (isset($e_date) &&
trim($e_date) !=
'') ? $e_date :
'';
1640 $l_user_per = $g_user->get_periode();
1643 $period =
new IPeriod(
"period");
1646 $period->value =
$def;
1647 $period->type =
OPEN;
1650 $l_form_per = $period->input();
1652 catch (Exception
$e)
1654 if ($e->getCode() == 1)
1656 echo _(
"Aucune période ouverte");
1661 $f_periode =
td(_(
"Période comptable") .
" $label " ).td( $l_form_per);
1664 $wPJ =
new IText(
'e_pj');
1665 $wPJ->readonly =
false;
1670 if ($g_parameter->MY_PJ_SUGGEST ==
'Y')
1674 $wPJ->value = (isset($e_pj)) ? $e_pj : $default_pj;
1677 $ret.=
'<td colspan="2" style="width:auto"> ' . _(
'Pièce') .
' : ' . $wPJ->input();
1683 $ret.=
'<td colspan="2" style="width:auto">';
1685 $wDescription =
new IText(
'desc');
1687 $wDescription->size =
"50";
1688 $wDescription->value = (isset(
$desc)) ?
$desc :
'';
1690 $ret.=$wDescription->input();
1695 $nb_row = (isset($nb_item) ) ? $nb_item : $this->
nb;
1698 $ret.=dossier::hidden();
1700 $ret.=dossier::hidden();
1705 if ($g_user->check_action(
FICADD) == 1)
1706 $ret.=$f_add_button->input();
1707 $ret.=
'<table id="quick_item" style="position:float;width:100%">';
1709 '<th style="text-align:left">Quickcode' . $info .
'</th>' .
1710 '<th style="text-align:left">' . _(
'Poste') . $info_poste .
'</th>' .
1711 '<th style="text-align:left">' . _(
'Libellé') .
'</th>' .
1712 '<th style="text-align:left">' . _(
'Montant') .
'</th>' .
1713 '<th style="text-align:left">' . _(
'Débit') .
'</th>' .
1717 for ($i = 0; $i <
$nb_row; $i++)
1721 $quick_code->set_dblclick(
"fill_ipopcard(this);");
1735 $quick_code->value = (isset(${
'qc_' . $i})) ? ${
'qc_' . $i} :
"";
1749 $poste->name =
'poste' . $i;
1750 $poste->set_attribute(
'jrn', $this->
id);
1751 $poste->set_attribute(
'ipopup',
'ipop_account');
1752 $poste->set_attribute(
'label',
'ld' . $i);
1753 $poste->set_attribute(
'account',
'poste' . $i);
1756 $poste->value = (isset(${
'poste' . $i})) ? ${
"poste" . $i} :
''
1758 $poste->dbl_click_history();
1765 $Poste->set_parameter(
'value',
$poste->value);
1766 $label = $Poste->get_lib();
1770 $line_desc =
new IText();
1771 $line_desc->name =
'ld' . $i;
1772 $line_desc->size = 30;
1773 $line_desc->value = (isset(${
"ld" . $i})) ? ${
"ld" . $i} :
1779 $amount->name =
'amount' . $i;
1780 $amount->value = (isset(${
'amount' . $i})) ? ${
"amount" . $i} :
''
1783 $amount->javascript =
' onChange="format_number(this);checkTotalDirect()"';
1786 $deb->name =
'ck' . $i;
1787 $deb->selected = (isset(${
'ck' . $i})) ?
true :
false;
1789 $deb->javascript =
' onChange="checkTotalDirect()"';
1794 '<script> document.getElementById(\'poste' . $i .
'\').onblur=
function(){
if (
trim(this.
value) !=\
'\') {
document.getElementById(\
'qc_' . $i .
'\').value=
"";}}</script>
' .
1796 $ret.='<
td>
' . $line_desc->input() . '</
td>
';
1797 $ret.='<
td>
' . $amount->input() . '</
td>
';
1798 $ret.='<
td>
' . $deb->input() . '</
td>
';
1800 // If readonly == 1 then show CA
1803 if (isset($this->with_concerned) && $this->with_concerned == true)
1805 $oRapt = new Acc_Reconciliation($this->db);
1806 $w = $oRapt->widget();
1807 $w->name = 'jrn_concerned
';
1808 $w->value = (isset($jrn_concerned)) ? $jrn_concerned : "";
1809 $ret.="Réconciliation/rapprochements : " . $w->input();
1811 $ret.= create_script("$('".$wDate->id."').focus()");
1822 function is_closed($p_periode)
1824 $per = new Periode($this->db);
1825 $per->set_jrn($this->id);
1826 $per->set_periode($p_periode);
1827 $ret = $per->is_closed();
1842 function verify($p_array)
1844 if (is_array($p_array ) == false || empty($p_array))
1845 throw new Exception ("Array empty");
1847 * Check needed value
1849 check_parameter($p_array,'p_jrn,e_date
');
1851 extract($p_array, EXTR_SKIP);
1857 /* check if we can write into this ledger */
1858 if ($g_user->check_jrn($p_jrn) != 'W
')
1859 throw new Exception(_('Accès interdit
'), 20);
1861 /* check for a double reload */
1862 if (isset($mt) && $this->db->count_sql('select jr_mt
from jrn where jr_mt=$1
', array($mt)) != 0)
1863 throw new Exception('Double Encodage
', 5);
1865 // Check the periode and the date
1866 if (isDate($e_date) == null)
1868 throw new Exception('Date invalide
', 2);
1870 $periode = new Periode($this->db);
1871 /* find the periode if we have enabled the check_periode
1872 * or if period is not set
1874 if ($this->check_periode() == false || ! isset ($p_array['period
']) )
1876 $periode->find_periode($e_date);
1880 $periode->p_id = $p_array['period
'];
1881 list ($min, $max) = $periode->get_date_limit();
1882 if (cmpDate($e_date, $min) < 0 ||
1883 cmpDate($e_date, $max) > 0)
1884 throw new Exception(_('Date et periode ne correspondent pas
'), 6);
1890 if ($this->is_closed($periode->p_id) == 1)
1892 throw new Exception('Periode fermee
', 6);
1894 /* check if we are using the strict mode */
1895 if ($this->check_strict() == true)
1897 /* if we use the strict mode, we get the date of the last
1899 $last_date = $this->get_last_date();
1900 if ($last_date != null && cmpDate($e_date, $last_date) < 0)
1901 throw new Exception(_('Vous utilisez le mode strict la dernière operation est la date du
')
1902 . $last_date . ' ' . _('vous ne pouvez pas encoder à une date antérieure
'), 15);
1905 for ($i = 0; $i < $nb_item; $i++)
1909 // Check the balance
1910 if (!isset(${'amount
' . $i}))
1913 $amount = round(${'amount
' . $i}, 2);
1914 $tot_deb+=(isset(${'ck
' . $i})) ? $amount : 0;
1915 $tot_cred+=(!isset(${'ck
' . $i})) ? $amount : 0;
1917 // Check if the card is permitted
1918 if (isset(${'qc_
' . $i}) && trim(${'qc_
' . $i}) != "")
1920 $f = new Fiche($this->db);
1921 $f->quick_code = ${'qc_
' . $i};
1922 if ($f->belong_ledger($p_jrn) < 0)
1923 throw new Exception("La fiche quick_code = " .
1924 $f->quick_code . " n'est pas dans ce journal
", 4);
1925 if (strlen(trim(${'qc_' . $i})) != 0 && isNumber(${'amount' . $i}) == 0)
1926 throw new Exception('Montant invalide', 3);
1928 $strPoste = $f->strAttribut(ATTR_DEF_ACCOUNT);
1929 if ($strPoste == '')
1930 throw new Exception(sprintf(_("La fiche %s
n'a pas de poste comptable"), ${"qc_" . $i}));
1932 $p = new Acc_Account_Ledger($this->db, $strPoste);
1933 if ($p->do_exist() == 0)
1934 throw new Exception(_('Poste Inexistant pour la fiche [
' . ${'qc_
' . $i} . ']
'), 4);
1937 // Check if the account is permitted
1938 if (isset(${'poste
' . $i}) && strlen(trim(${'poste
' . $i})) != 0)
1940 $p = new Acc_Account_Ledger($this->db, ${'poste
' . $i});
1941 if ($p->belong_ledger($p_jrn) < 0)
1942 throw new Exception(_("Le poste") . " " . $p->id . " " . _("n'est pas dans ce journal
"), 5);
1943 if (strlen(trim(${'poste' . $i})) != 0 && isNumber(${'amount' . $i}) == 0)
1944 throw new Exception(_('Poste invalide [' . ${'poste' . $i} . ']'), 3);
1945 if ($p->do_exist() == 0)
1946 throw new Exception(_('Poste Inexistant [' . ${'poste' . $i} . ']'), 4);
1947 $card_id = $p->find_card();
1948 if (!empty($card_id))
1950 $str_msg = " Le poste
" . $p->id . " appartient à
" . count($card_id) . " fiche(s) dont :";
1954 $card =
new Fiche($this->
db, $card_id[$x][
'f_id']);
1966 throw new Exception(_(
"Balance incorrecte ") .
" debit = $tot_deb credit=$tot_cred ", 1);
1987 $num = $this->
db->get_next_seq(
's_internal');
1988 $atype = $this->get_propertie();
1989 $type = substr($atype[
'jrn_def_code'], 0, 1);
1990 $internal_code = sprintf(
"%s%06X",
$type,
$num);
1991 $this->jr_internal = $internal_code;
1992 return $internal_code;
2007 throw new Exception(
'save cannot use a empty array');
2015 echo $this->display_warning(
$msg, _(
"Attention : il vaut mieux utiliser les fiches que les postes comptables "));
2019 $seq = $this->
db->get_next_seq(
's_grpt');
2020 $internal = $this->compute_internal_code(
$seq);
2022 $group = $this->
db->get_next_seq(
"s_oa_group");
2038 for ($i = 0; $i < $nb_item; $i++)
2040 if (!isset(${
'qc_' . $i}) && !isset(${
'poste' . $i}))
2045 if (isset(${
'qc_' . $i}))
2048 $qc->get_by_qcode(${
'qc_' . $i},
false);
2051 if (strpos($sposte,
',') != 0)
2053 $array = explode(
",", $sposte);
2060 throw new Exception(sprintf(_(
"La fiche %s n'a pas de poste comptable"), ${
"qc_" . $i}));
2066 $poste = ${
'poste' . $i};
2069 $acc_op->date = $e_date;
2073 $acc_op->desc = null;
2074 if (strlen(
trim(${
'ld' . $i})) != 0)
2075 $acc_op->desc = ${
'ld' . $i};
2076 $acc_op->amount = round(${
'amount' . $i}, 2);
2077 $acc_op->grpt =
$seq;
2080 $acc_op->type = (isset(${
'ck' . $i})) ?
'd' :
'c';
2082 $j_id = $acc_op->insert_jrnx();
2083 $tot_amount+=round($acc_op->amount, 2);
2084 $tot_deb+=($acc_op->type ==
'd') ? $acc_op->amount : 0;
2085 $tot_cred+=($acc_op->type ==
'c') ? $acc_op->amount : 0;
2086 if ($g_parameter->MY_ANALYTIC !=
"nu")
2088 if (preg_match(
"/^[6,7]+/",
$poste) == 1)
2093 $op->oa_group = $group;
2095 $op->oa_date = $e_date;
2096 $op->oa_debit = ($acc_op->type ==
'd' ) ?
't' :
'f';
2107 $acc_end->date = $e_date;
2108 $acc_end->desc =
$desc;
2109 $acc_end->grpt =
$seq;
2112 $jr_id = $acc_end->insert_jrn();
2115 throw new Exception(_(
'Balance incorrecte'));
2116 $acc_end->pj = $e_pj;
2119 if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(
trim($e_pj)) != 0)
2121 $this->inc_seq_pj();
2124 $this->pj = $acc_end->set_pj();
2126 $this->
db->exec_sql(
"update jrn set jr_internal='" . $internal .
"' where " .
2127 " jr_grpt_id = " .
$seq);
2128 $this->
internal = $internal;
2131 if (isset ($opd_name) &&
trim($opd_name) !=
"" ){
2139 $orap =
new acc_reconciliation($this->
db);
2142 $orap->insert($jrn_concerned);
2147 if (isset($_FILES[
"pj"]))
2149 $this->
db->save_receipt($seq);
2153 catch (Exception
$a)
2157 catch (Exception
$e)
2159 $this->
db->rollback();
2160 echo _(
'OPERATION ANNULEE ');
2162 echo __FILE__ . __LINE__ . $e->getMessage();
2165 $this->
db->commit();
2191 $Ret = $p_cn->count_sql(
"select * from jrn_def where jrn_def_type='" .
$p_type .
"'");
2219 list($ad) = sscanf(
$name,
"set_jr_id%d");
2222 $sql =
"update jrn set jr_rapt='' where jr_id=$ad";
2228 list (
$id) = sscanf(
$name,
"rd_paid%d");
2232 $sql =
"update jrn set jr_rapt='paid' where jr_id=$id";
2239 if (!isset($this->grpt_id))
2240 throw new Exception((
'ERREUR ' . __FILE__ .
":" . __LINE__));
2241 $Res = $this->
db->exec_sql(
"update jrn set jr_internal='" . $p_internal .
"' where " .
2242 " jr_grpt_id = " . $this->grpt_id);
2255 if ($p_ledger_type ==
'FIN')
2261 $array=array_merge ( $array , $fiche_def_ref->get_by_modele(
FICHE_TYPE_EMPL));
2265 if ($p_ledger_type ==
'ODS')
2267 $result=$this->
db->get_array(
'select fd_id from fiche_def');
2268 for ($i = 0;$i<count(
$result);$i++ )
2275 switch($p_ledger_type)
2286 throw new Exception(_(
'get_default_card p_ledger_side is invalide ['.$p_ledger_type.
']'));
2289 } elseif ($p_side ==
'C')
2291 switch($p_ledger_type)
2301 throw new Exception(_(
'get_default_card p_ledger_side is invalide ['.$p_ledger_type.
']'));
2325 $sql =
"select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred " .
2326 " from jrn_def where " .
2327 " jrn_def_id = $1 ";
2329 $r = $this->
db->exec_sql(
$sql, array($this->
id));
2336 foreach (
$res as $item)
2338 if (strlen(
trim($item[
'deb'])) != 0)
2340 $card.=$comma . $item[
'deb'];
2343 if (strlen(
trim($item[
'cred'])) !=
'')
2345 $card.=$comma . $item[
'cred'];
2365 $sql =
"select sum(a.montant) as solde, j_poste, j_qcode
2367 (select j_id, case when j_debit='t' then j_montant
2368 else j_montant * (-1) end as montant
2370 join jrnx using (j_id)
2371 join parm_periode on (j_tech_per = p_id )
2374 and j_poste::text not like '7%'
2375 and j_poste::text not like '6%'
2376 group by j_poste,j_qcode
2377 having (sum(a.montant) != 0 ) order by 1 desc";
2390 if ($g_parameter->MY_STRICT ==
'Y')
2392 if ($g_parameter->MY_STRICT ==
'N')
2394 throw new Exception(
"Valeur invalid " . __FILE__ .
':' . __LINE__);
2406 if ($g_parameter->MY_CHECK_PERIODE ==
'Y')
2408 if ($g_parameter->MY_CHECK_PERIODE ==
'N')
2410 throw new Exception(
"Valeur invalid " . __FILE__ .
':' . __LINE__);
2420 throw new Exception(__FILE__ .
":" . __LINE__ .
"Journal incorrect ");
2421 $sql =
"select to_char(max(jr_date),'DD.MM.YYYY') from jrn where jr_def_id=$1";
2422 $date = $this->
db->get_value(
$sql, array($this->
id));
2435 $sql =
'select jr_id from jrn where jr_internal=$1';
2436 $value = $this->
db->get_value(
$sql, array($p_internal));
2454 $doc->f_id = $e_client;
2455 $doc->md_id = $gen_doc;
2461 $doc->MoveDocumentPj($internal);
2463 if (!isset($e_comm) || strlen(
trim($e_comm)) == 0)
2465 $sql =
"update jrn set jr_comment=' document " .
$doc->d_number .
"' where jr_internal='$internal'";
2466 $this->
db->exec_sql(
$sql);
2468 return h(
$doc->d_name .
' (' .
$doc->d_filename .
')');
2484 $empl->get_by_qcode($e_mp_qcode);
2487 throw new Exception(_(
"Celui qui paie n' a pas de poste comptable"), 20);
2492 if (strpos($sposte,
',') != 0)
2494 $array = explode(
',', $sposte);
2499 $poste_val = $sposte;
2502 if (
$poste->load() ==
false)
2504 throw new Exception(sprintf(_(
"Pour la fiche %s le poste comptable [%s] n'existe pas"),$empl->quick_code,
$poste->id ), 9);
2514 $sql =
"select nextval('s_jrn_pj" . $this->
id .
"')";
2515 $this->
db->exec_sql(
$sql);
2537 $bledger_param= json_encode(array(
2540 'all_type'=>$all_type_ledger,
2544 $bledger_param= str_replace(
'"',
"'", $bledger_param);
2546 $bledger->label=_(
"choix des journaux");
2547 $bledger->javascript=
" show_ledger_choice($bledger_param)";
2548 $f_ledger=$bledger->input();
2560 $period = $g_user->get_periode();
2564 $date_end = $per_end->last_day();
2568 $f_date_start =
new IDate(
'date_start');
2572 $f_date_start->value =
$_REQUEST[
'date_start'];
2580 $f_date_end =
new IDate(
'date_end');
2584 $f_date_end->value =
$_REQUEST[
'date_end'];
2588 $f_date_end->value = $date_end;
2591 $f_date_paid_start=
new IDate(
'date_paid_start');
2592 $f_date_paid_end=
new IDate(
'date_paid_end');
2594 $f_date_paid_start->value=(isset(
$_REQUEST[
'date_paid_start']))?
$_REQUEST[
'date_paid_start']:
'';
2595 $f_date_paid_end->value=(isset(
$_REQUEST[
'date_paid_end']))?
$_REQUEST[
'date_paid_end']:
'';
2598 $f_descript =
new IText(
'desc');
2599 $f_descript->size = 40;
2606 $f_amount_min =
new INum(
'amount_min');
2607 $f_amount_min->value = (isset(
$_REQUEST[
'amount_min'])) ? abs(
$_REQUEST[
'amount_min']) : 0;
2608 $f_amount_max =
new INum(
'amount_max');
2609 $f_amount_max->value = (isset(
$_REQUEST[
'amount_max'])) ? abs(
$_REQUEST[
'amount_max']) : 0;
2614 $f_qcode->set_attribute(
'typecard',
'all');
2619 $f_qcode->set_dblclick(
"fill_ipopcard(this);");
2622 $f_qcode->set_function(
'fill_data');
2623 $f_qcode->javascript = sprintf(
' onchange="fill_data_onchange(%s);" ', $f_qcode->name);
2631 $f_accounting =
new IPoste(
'accounting');
2632 $f_accounting->value = (isset(
$_REQUEST[
'accounting'])) ?
$_REQUEST[
'accounting'] :
'';
2633 if ($this->
id == -1)
2637 $f_accounting->set_attribute(
'jrn',
$jrn);
2638 $f_accounting->set_attribute(
'ipopup',
'ipop_account');
2639 $f_accounting->set_attribute(
'label',
'ld');
2640 $f_accounting->set_attribute(
'account',
'accounting');
2643 $f_paid =
new ICheckbox(
'unpaid');
2644 $f_paid->selected = (isset(
$_REQUEST[
'unpaid'])) ?
true :
false;
2646 $r.=dossier::hidden();
2650 require_once NOALYSS_TEMPLATE.
'/ledger_search.php';
2651 $r.=ob_get_contents();
2686 $sql =
"select jr_id ,
2688 substr(jr_comment,1,60) as jr_comment,
2689 to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
2690 to_char(jr_date,'DD.MM.YY') as str_jr_date,
2691 jr_date as jr_date_order,
2706 when jrn_def_type='VEN' then
2707 (select ad_value from fiche_detail where ad_id=1
2708 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2709 when jrn_def_type = 'ACH' then
2710 (select ad_value from fiche_detail where ad_id=1
2711 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2712 when jrn_def_type = 'FIN' then
2713 (select ad_value from fiche_detail where ad_id=1
2714 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
2717 when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2718 when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2719 when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=32 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
2722 when jrn_def_type='VEN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2723 when jrn_def_type = 'ACH' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
2724 when jrn_def_type = 'FIN' then (select ad_value from fiche_detail where ad_id=23 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
2727 when jrn_def_type='VEN' then
2728 (select sum(qs_price)+sum(vat) from
2729 (select qs_internal,qs_price,case when qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where qs_internal=X.jr_internal) as ven_invoice
2731 when jrn_def_type = 'ACH' then
2733 select sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
2735 (select qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
2738 end as total_invoice,
2740 to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
2742 jrn as X left join jrn_note using(jr_id)
2743 join jrn_def on jrn_def_id=jr_def_id
2744 join parm_periode on p_id=jr_tech_per";
2750 $r_jrn = (isset(${
$op.
"r_jrn"})) ? ${
$op.
"r_jrn"} : -1;
2766 if (isset($qcodesearch_op))
2767 $qcode = $qcodesearch_op;
2768 $accounting = (isset($accounting)) ? $accounting :
"";
2815 for ($i = 0; $i < count(
$r_jrn); $i++)
2820 $fil_ledger.=
$sp .
$a;
2824 $fil_ledger =
' jrn_def_id in (' . $fil_ledger .
')';
2836 $amount_min = abs(
toNumber($amount_min));
2837 $amount_max = abs(
toNumber($amount_max));
2838 if ($amount_min > 0 &&
isNumber($amount_min))
2840 $fil_amount = $and .
' jr_montant >=' . $amount_min;
2843 if ($amount_max > 0 &&
isNumber($amount_max))
2845 $fil_amount.=$and .
' jr_montant <=' . $amount_max;
2855 bccomp($amount_min, $amount_max, 2) == 0)
2857 $fil_amount = $and .
' ( ';
2860 $fil_amount .=
'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = ' . $amount_min .
') ';
2863 $fil_amount .=
' or ';
2864 $fil_amount .=
' jr_montant = '.$amount_min;
2872 $fil_date = $and .
" jr_date >= to_date('" .
$date_start .
"','DD.MM.YYYY')";
2875 if (isset($date_end) &&
isDate($date_end) != null)
2877 $fil_date.=$and .
" jr_date <= to_date('" . $date_end .
"','DD.MM.YYYY')";
2881 if (isset($date_paid_start) &&
isDate($date_paid_start) != null)
2883 $fil_date_paid = $and .
" jr_date_paid >= to_date('" . $date_paid_start .
"','DD.MM.YYYY')";
2886 if (isset($date_paid_end) &&
isDate($date_paid_end) != null)
2888 $fil_date_paid.=$and .
" jr_date_paid <= to_date('" . $date_paid_end .
"','DD.MM.YYYY')";
2895 $fil_desc = $and .
" ( upper(jr_comment) like upper('%" .
$desc .
"%') or upper(jr_pj_number) like upper('%" .
$desc .
"%') " .
2896 " or upper(jr_internal) like upper('%" .
$desc .
"%')
2897 or jr_grpt_id in (select j_grpt from jrnx where j_text ~* '" .
$desc .
"')
2898 or jr_id in (select jr_id from jrn_info where ji_value is not null and ji_value ~* '$desc')
2903 if (isset($accounting) && $accounting != null)
2905 $fil_account = $and .
" jr_grpt_id in (select j_grpt
2906 from jrnx where j_poste::text like '" .
sql_string($accounting) .
"%' ) ";
2910 if (isset($qcodesearch_op))
2911 $qcode = $qcodesearch_op;
2914 $fil_qcode = $and .
" jr_grpt_id in ( select j_grpt from
2932 $fil_sec = $and .
" jr_def_id in ( select uj_jrn_id " .
2933 " from user_sec_jrn where " .
2934 " uj_login='" . $_SESSION[
'g_user'] .
"'" .
2935 " and uj_priv in ('R','W'))";
2937 $where = $fil_ledger . $fil_amount . $fil_date . $fil_desc . $fil_sec . $fil_amount . $fil_qcode . $fil_paid . $fil_account.$fil_date_paid;
2938 $sql.=
" where " . $where;
2939 return array(
$sql, $where);
2957 $r.=
'<div id="search_form" style="display:none">';
2959 $r.=
h2(
'Recherche',
'class="title"');
2960 $r.=
'<FORM METHOD="GET">';
2961 $r.=$this->search_form(
$type);
2979 $button->label = _(
"Filtrer");
2980 $button->javascript =
"toggleHideShow('search_form','tfs');";
2982 $r.=$button->input();
2995 $filter_ledger = $g_user->get_ledger_sql(
'ALL', 3);
2996 $filter_ledger = str_replace(
'jrn_def_id',
'jr_def_id', $filter_ledger);
2998 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
3000 join jrn_def on (jrn_def_id=jr_def_id)
3001 where $filter_ledger
3002 order by jr_date desc , substring(jr_pj_number,'[0-9]+$')::numeric desc limit $p_limit";
3019 return $this->
db->get_value(
'select jr_grpt_id from jrn where jr_internal=$1', array($p_value));
3032 $jrn = ($this->
id == 0) ?
'and ' . $g_user->get_ledger_sql() :
' and jr_def_id = ' .
$this->id;
3033 $sql =
"select jr_id as id ,jr_internal as internal, " .
3034 "jr_pj_number as pj,jr_grpt_id," .
3035 " to_char(jr_date,'DDMMYY') as date_fmt, " .
3036 " jr_comment as comment, jr_montant as montant ," .
3037 " jr_grpt_id,jr_def_id" .
3038 " from jrn join jrn_def on (jr_def_id=jrn_def_id) where " .
3039 " jr_date >= (select p_start from parm_periode where p_id = $1)
3040 and jr_date <= (select p_end from parm_periode where p_id = $2)" .
3041 ' ' .
$jrn .
' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc';
3042 $ret = $this->
db->get_array(
$sql, array($p_from, $p_to));
3052 if ($this->
type ==
'ACH')
3054 $array = $this->
db->get_array(
"select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
3055 " and exists (select qp_vat_code from quant_purchase
3056 where qp_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id", array($this->
id));
3058 if ($this->
type ==
'VEN')
3060 $array = $this->
db->get_array(
"select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 " .
3061 " and exists (select qs_vat_code from quant_sold
3062 where qs_vat_code=tva_id and exists (select j_id from jrnx where j_jrn_def = $1)) order by tva_id", array($this->
id));
3085 if ($this->
type ==
'ACH')
3087 $array = $this->
db->get_array(
'select sum(qp_price) as price,sum(qp_vat) as vat ' .
3088 ',sum(coalesce(qp_nd_amount,0)+coalesce(qp_dep_priv,0)) as priv' .
3089 ',sum(coalesce(qp_nd_tva_recup,0)+coalesce(qp_nd_tva,0)) as tva_nd' .
3090 ',sum(qp_vat_sided) as tva_np' .
3091 ' from quant_purchase join jrnx using(j_id)
3092 where j_grpt=$1 ', array($p_jr_id));
3095 if ($this->
type ==
'VEN')
3097 $array = $this->
db->get_array(
'select sum(qs_price) as price,sum(qs_vat) as vat ' .
3100 ',sum(qs_vat_sided) as tva_np' .
3101 ' from quant_sold join jrnx using(j_id)
3102 where j_grpt=$1 ', array($p_jr_id));
3121 if ($this->
type ==
'ACH')
3123 $array = $this->
db->get_array(
'select coalesce(sum(qp_vat),0) as sum_vat,tva_id
3124 from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
3125 where tva_rate !=0.0 and j_grpt=$1 group by tva_id', array($p_jr_id));
3127 if ($this->
type ==
'VEN')
3129 $array = $this->
db->get_array(
'select coalesce(sum(qs_vat),0) as sum_vat,tva_id
3130 from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
3131 where tva_rate !=0.0 and j_grpt=$1 group by tva_id', array($p_jr_id));
3169 $exercise =
$periode->get_exercice();
3172 $min_date=
$min->first_day();
3174 $periode_max=
new Periode($this->
db,$p_to);
3175 $max_date=$periode_max->first_day();
3178 if ($this->
type ==
'ACH')
3181 $sql =
"select coalesce(sum(qp_price),0) as price" .
3182 " ,coalesce(sum(qp_vat),0) as vat " .
3183 ',coalesce(sum(qp_dep_priv),0) as priv' .
3184 ',coalesce(sum(qp_vat_sided),0) as reversed' .
3185 ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' .
3186 ',coalesce(sum(qp_vat_sided),0) as tva_np' .
3187 ' from quant_purchase join jrnx using(j_id) ' .
3188 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
3189 ' and j_jrn_def = $3';
3190 $array = $this->
db->get_array(
$sql, array($min_date, $max_date,$this->
id));
3194 $array = $this->
db->get_array(
"select coalesce(sum(qp_vat),0) as sum_vat,tva_id
3195 from quant_purchase as p right join tva_rate on (qp_vat_code=tva_id) join jrnx using(j_id)
3196 where tva_rate !=0 and j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
3199 array($min_date, $max_date,$this->
id));
3202 if ($this->
type ==
'VEN')
3205 $sql =
"select coalesce(sum(qs_price),0) as price" .
3206 " ,coalesce(sum(qs_vat),0) as vat " .
3209 ',coalesce(sum(qs_vat_sided),0) as tva_np' .
3210 ' from quant_sold join jrnx using(j_id) ' .
3211 " where j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY') ".
3212 ' and j_jrn_def = $3';
3213 $array = $this->
db->get_array(
$sql, array($min_date, $max_date,$this->
id));
3216 $array = $this->
db->get_array(
"select coalesce(sum(qs_vat),0) as sum_vat,tva_id
3217 from quant_sold as p right join tva_rate on (qs_vat_code=tva_id) join jrnx using(j_id)
3218 where tva_rate !=0 and
3219 j_date >= to_date($1,'DD.MM.YYYY') and j_date < to_date($2,'DD.MM.YYYY')
3221 group by tva_id", array($min_date, $max_date,$this->
id));
3224 if ($this->
type==
"FIN")
3233 $cond=sprintf(
" j_jrn_def <> %d and j_date >= to_date('%s','DD.MM.YYYY') and j_date < to_date('%s','DD.MM.YYYY') ",$this->
id,$min_date,$max_date);
3234 $saldo = $bank_card->get_bk_balance ($cond);
3250 echo Acc_Reconciliation::$javascript;
3253 $_SESSION[
'g_user'] = NOALYSS_ADMINISTRATOR ;
3254 $_SESSION[
'g_pass'] =
'phpcompta';
3258 $a->with_concerned =
true;
3260 echo
'<FORM method="post">';
3261 echo
$a->select_ledger()->input();
3267 echo
'<form method="post">';
3268 echo
$a->show_form();
3274 echo dossier::hidden();
3275 echo
'<input type="hidden" value="' .
$id .
'" name="p_jrn">';
3278 $op->od_direct =
't';
3279 if (
$op->count() != 0)
3281 echo
HtmlInput::submit(
'use_opd',
'Utilisez une opération prédéfinie',
"",
"smallbutton");
3282 echo
$op->show_button();
3288 if (isset(
$_POST[
'post_id']))
3291 echo
'<form method="post">';
3293 echo
HtmlInput::button(
'add',
'Ajout d\'une ligne',
'onClick="quick_writing_add_row()"');
3298 if (isset(
$_POST[
'save_it']))
3307 catch (Exception
$e)
3309 alert($e->getMessage());
3310 echo
'<form method="post">';
3320 if (isset(
$_GET[
'use_opd']))
3322 $op =
new Pre_op_advanced(
$cn);
3328 echo
'<FORM method="post">';
3338 if ($pCase ==
'search')
3343 $_SESSION[
'g_user'] = NOALYSS_ADMINISTRATOR;
3344 $_SESSION[
'g_pass'] =
'phpcompta';
3345 echo
$ledger->search_form(
'ALL');
3351 if ($pCase ==
'reverse')
3354 $jr_internal =
'OD-01-272';
3358 $jrn_def_id =
$cn->get_value(
'select jr_def_id from jrn where jr_internal=$1', array($jr_internal));
3360 $ledger->jr_id =
$cn->get_value(
'select jr_id from jrn where jr_internal=$1', array($jr_internal));
3362 echo
"Ouvrez le fichier " . __FILE__ .
" à la ligne " . __LINE__ .
" pour changer jr_internal et vérifier le résultat de l'extourne";
3364 $ledger->reverse(
'01.07.2010');
3366 catch (Exception
$e)
3382 array(
'cat' =>
'VEN',
'name' => _(
"Journaux de vente")),
3383 array(
'cat' =>
'ACH',
'name' => _(
"Journaux d'achat")),
3384 array(
'cat' =>
'FIN',
'name' => _(
"Journaux Financier")),
3385 array(
'cat' =>
'ODS',
'name' => _(
"Journaux d'Opérations diverses"))
3397 switch ($p_jrn_type)
3400 $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', array(
$jr_id));
3403 $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', array(
$jr_id));
3407 $tiers = $this->
db->get_value(
'select qf_other from quant_fin where jr_id=$1', array(
$jr_id));
3410 if ($this->
db->count() == 0)
3421 if ($p_jrn_type ==
'ODS')
3423 $tiers = $this->get_tiers_id($p_jrn_type,
$jr_id);
3424 if ( $tiers == 0 )
return "";
3426 $name = $this->
db->get_value(
'select ad_value from fiche_detail where ad_id=1 and f_id=$1', array($tiers));
3427 $first_name = $this->
db->get_value(
'select ad_value from fiche_detail where ad_id=32 and f_id=$1', array($tiers));
3428 return $name .
' ' . $first_name;
3442 $r.=
'<TABLE id="cfgledger_table_id" class="vert_mtitle">';
3443 $r.=
'<TR><TD class="first"><A HREF="' .
$base_url .
'&sa=add">' . _(
'Ajout journal') .
' </A></TD></TR>';
3444 $ret = $this->
db->exec_sql(
"select distinct jrn_def_id,jrn_def_name,
3445 jrn_def_class_deb,jrn_def_class_cred,jrn_def_type
3446 from jrn_def order by jrn_def_name");
3450 for ($i = 0; $i <
$Max; $i++)
3453 $url =
$base_url .
"&sa=detail&p_jrn=" . $l_line[
'jrn_def_id'];
3454 $r.=sprintf(
'<TR><TD><A HREF="%s">%s</A></TD></TR>',
$url,
h($l_line[
'jrn_def_name']).
' ('.$l_line[
'jrn_def_type'].
')');
3466 if ($this->load() == -1)
3468 throw new Exception(_(
"Journal n'existe pas"), -1);
3470 $type = $this->jrn_def_type;
3472 $code = $this->jrn_def_code;
3476 $wSearch->set_attribute(
'ipopup',
'ipop_account');
3477 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
3478 $wSearch->set_attribute(
'no_overwrite',
'1');
3479 $wSearch->set_attribute(
'noquery',
'1');
3480 $wSearch->table = 3;
3481 $wSearch->name =
"p_jrn_class_deb";
3482 $wSearch->size = 20;
3483 $wSearch->value = $this->jrn_def_class_deb;
3484 $search = $wSearch->input();
3486 $wPjPref =
new IText();
3487 $wPjPref->name =
'jrn_def_pj_pref';
3488 $wPjPref->value = $this->jrn_def_pj_pref;
3489 $pj_pref = $wPjPref->input();
3491 $wPjSeq =
new INum();
3493 $wPjSeq->name =
'jrn_def_pj_seq';
3495 $last_seq = $this->get_last_pj();
3505 $min_row =
new INum(
"min_row",$this->jrn_deb_max_line);
3509 $description->style=
'class="itextarea" style="margin:0px;"';
3514 $card = $this->get_fiche_def();
3515 $rdeb = explode(
',', $card[
'deb']);
3516 $rcred = explode(
',', $card[
'cred']);
3518 $num_op =
new ICheckBox(
'numb_operation');
3519 if ($this->jrn_def_num_op == 1)
3520 $num_op->selected =
true;
3525 $f_id = $this->jrn_def_bank;
3529 $qcode_bank = $fBank->get_quick_code();
3535 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
3564 extract(
$array, EXTR_SKIP);
3568 throw new Exception(
"Id invalide");
3569 if (
isNumber($p_jrn_deb_max_line) == 0)
3570 throw new Exception(_(
"Nombre de ligne incorrect"));
3571 if (
trim($p_jrn_name) ==
"")
3572 throw new Exception(
"Nom de journal invalide");
3573 if ($this->
db->get_value(
"select count(*) from jrn_def where jrn_def_name=$1 and jrn_Def_id<>$2", array($p_jrn_name,
$p_jrn)) > 0)
3574 throw new Exception(_(
"Un journal avec ce nom existe déjà"));
3575 if ($p_jrn_type ==
'FIN')
3580 throw new Exception(_(
"Aucun compte en banque n'est donné"));
3582 if ($p_jrn_type ==
"-1") {
3583 throw new Exception(_(
'Choix du type de journal est obligatoire'));
3586 catch (Exception
$e)
3600 throw new Exception(
'save cannot use a empty array');
3602 extract(
$array, EXTR_SKIP);
3603 $this->jrn_def_id =
$p_jrn;
3604 $this->jrn_def_name = $p_jrn_name;
3605 $this->jrn_def_ech_lib = $p_ech_lib;
3606 $this->jrn_def_max_line_deb = ($p_jrn_deb_max_line<1)?1:$p_jrn_deb_max_line;
3607 $this->jrn_def_type = $p_jrn_type;
3608 $this->jrn_def_pj_pref = $jrn_def_pj_pref;
3609 $this->jrn_deb_max_line=($min_row<1)?1:$min_row;
3610 $this->jrn_def_description=$p_description;
3611 switch ($this->jrn_def_type)
3614 $this->jrn_def_fiche_cred = (isset($ACH_FICHECRED)) ? join($ACH_FICHECRED,
',') :
'';
3615 $this->jrn_def_fiche_deb = (isset($ACH_FICHEDEB)) ? join($ACH_FICHEDEB,
',') :
"";
3618 $this->jrn_def_fiche_cred = (isset($VEN_FICHECRED)) ? join($VEN_FICHECRED,
',') :
'';
3619 $this->jrn_def_fiche_deb = (isset($VEN_FICHEDEB)) ? join($VEN_FICHEDEB,
',') :
"";
3623 $this->jrn_def_class_deb = $p_jrn_class_deb;
3624 $this->jrn_def_fiche_deb = (isset($ODS_FICHEDEB)) ? join($ODS_FICHEDEB,
',') :
'';;
3625 $this->jrn_def_fiche_cred = null;
3632 $this->jrn_def_bank = $bank;
3633 $this->jrn_def_fiche_deb = (isset($FIN_FICHEDEB)) ? join($FIN_FICHEDEB,
',') :
"";
3635 throw new Exception(_(
"Aucun compte en banque n'est donné"));
3636 $this->jrn_def_num_op = (isset($numb_operation)) ? 1 : 0;
3642 if ($jrn_def_pj_seq != 0)
3644 $Res = $this->
db->alter_seq(
"s_jrn_pj" .
$p_jrn, $jrn_def_pj_seq);
3651 $r.=
'<div id="payment"> ';
3652 $r.=
'<h2> ' . _(
'Payé par') .
' </h2>';
3654 $mp->set_parameter(
'ledger_source', $this->
id);
3655 $r.=$mp->select($p_selected);
3675 $f_add_button->label=_(
'Créer une nouvelle fiche');
3676 $f_add_button->tabindex=-1;
3677 $f_add_button->set_attribute(
'jrn',-1);
3678 $f_add_button->javascript=
" this.jrn=-1;select_card_type({type_cat:4});";
3681 if ($g_user->check_action(
FICADD)==1)
3683 $str_add_button=$f_add_button->input();
3686 $wSearch->table = 3;
3687 $wSearch->set_attribute(
'ipopup',
'ipop_account');
3688 $wSearch->set_attribute(
'account',
'p_jrn_class_deb');
3689 $wSearch->set_attribute(
'no_overwrite',
'1');
3690 $wSearch->set_attribute(
'noquery',
'1');
3692 $wSearch->name =
"p_jrn_class_deb";
3693 $wSearch->size = 20;
3695 $search = $wSearch->input();
3697 $default_deb_purchase = $this->get_default_card(
'ACH',
'D');
3698 $default_cred_purchase = $this->get_default_card(
'ACH',
'C');
3701 $default_deb_sale = $this->get_default_card(
'VEN',
'D');
3702 $default_cred_sale = $this->get_default_card(
'VEN',
'C');
3705 $default_fin = $this->get_default_card(
"FIN",
"");
3708 $default_ods = $this->get_default_card(
"ODS",
"");
3719 $name = $previous_p_jrn_name;
3722 $a_jrn= $this->
db->make_array(
"select '-1',' -- "._(
"choix du type de journal").
" -- ' union select jrn_type_id,jrn_desc from jrn_type");
3723 $wType->selected=
'-1';
3724 $wType->value =$a_jrn;
3725 $wType->name =
"p_jrn_type";
3726 $wType->id=
"p_jrn_type_select_id";
3727 $wType->javascript=
' onchange="show_ledger_div()"';
3728 $wType->selected=$default_type;
3729 $type = $wType->input();
3730 $rcred = $rdeb = array();
3731 $wPjPref =
new IText();
3732 $wPjPref->name =
'jrn_def_pj_pref';
3733 $wPjPref->value=$previous_jrn_def_pj_pref;
3734 $pj_pref = $wPjPref->input();
3739 $description->style=
'class="itextarea" style="margin:0px;"';
3745 $num_op =
new ICheckBox(
'numb_operation');
3746 echo dossier::hidden();
3753 require_once NOALYSS_TEMPLATE.
'/param_jrn.php';
3764 extract(
$array, EXTR_SKIP);
3765 $this->jrn_def_id = -1;
3766 $this->jrn_def_name = $p_jrn_name;
3767 $this->jrn_def_ech_lib = $p_ech_lib;
3768 $this->jrn_def_max_line_deb = $p_jrn_deb_max_line;
3769 $this->jrn_def_type = $p_jrn_type;
3770 $this->jrn_def_pj_pref = $jrn_def_pj_pref;
3771 $this->jrn_deb_max_line=$min_row;
3773 $this->jrn_def_description=$p_description;
3774 switch ($this->jrn_def_type)
3777 $this->jrn_def_fiche_cred = (isset($ACH_FICHECRED)) ? join($ACH_FICHECRED,
',') :
'';
3778 $this->jrn_def_fiche_deb = (isset($ACH_FICHEDEB)) ? join($ACH_FICHEDEB,
',') :
"";
3781 $this->jrn_def_fiche_cred = (isset($VEN_FICHECRED)) ? join($VEN_FICHECRED,
',') :
'';
3782 $this->jrn_def_fiche_deb = (isset($VEN_FICHEDEB)) ? join($VEN_FICHEDEB,
',') :
"";
3786 $this->jrn_def_class_deb = $p_jrn_class_deb;
3787 $this->jrn_def_fiche_deb = (isset($ODS_FICHEDEB)) ? join($ODS_FICHEDEB,
',') :
'';;
3788 $this->jrn_def_fiche_cred = null;
3794 $this->jrn_def_bank = $bank;
3795 $this->jrn_def_fiche_deb = (isset($FIN_FICHEDEB)) ? join($FIN_FICHEDEB,
',') :
"";
3797 throw new Exception(_(
"Aucun compte en banque n'est donné"));
3798 $this->jrn_def_num_op = (isset($numb_operation)) ? 1 : 0;
3813 if ($this->
db->get_value(
"select count(jr_id) from jrn where jr_def_id=$1", array($this->jrn_def_id)) > 0)
3814 throw new Exception(_(
"Impossible d'effacer un journal qui contient des opérations"));
3817 catch (Exception
$e)
3836 switch ($p_ledger_type)
3839 $filter=$g_user->get_ledger_sql(
'ACH',3);
3842 $filter=$g_user->get_ledger_sql(
'VEN',3);
3845 throw new Exception (
'Ledger_type invalid : '.$p_ledger_type);
3849 $sql =
"select jr_id, jr_internal, jr_date, jr_comment,jr_pj_number,jr_montant
3851 join jrn_def on (jrn_def_id=jr_def_id)
3854 and jr_ech $sql_op to_date($1,'DD.MM.YYYY')
3855 and coalesce (jr_rapt,'xx') <> 'paid'
3866 $array=$this->get_operation_date(Date(
'd.m.Y'),
'ACH',
'=');
3874 $array=$this->get_operation_date(Date(
'd.m.Y'),
'ACH',
'<');
3882 $array=$this->get_operation_date(Date(
'd.m.Y'),
'VEN',
'=');
3890 $array=$this->get_operation_date(Date(
'd.m.Y'),
'VEN',
'<');
3896 if (
isNumber($p_ag_id)==0)
return null;
3897 if (! $g_user->can_read_action($p_ag_id)) die (_(
'Action non accessible'));
3901 $tiers_id=$this->
db->get_value(
'select f_id_dest from action_gestion where ag_id=$1',array($p_ag_id));
3902 if ( $this->
db->size() !=0 )
3903 $qcode=$this->
db->get_value(
'select j_qcode from vw_poste_qcode where f_id=$1',array($tiers_id));
3907 $comment=$this->
db->get_value(
'select ag_title from action_gestion where ag_id=$1',array($p_ag_id));
3912 $a_item=$this->
db->get_array(
'select f_id,ad_text,ad_pu,ad_quant,ad_tva_id,ad_tva_amount,j_qcode
3915 left join vw_poste_qcode using(f_id)
3917 ag_id=$1',array($p_ag_id));
3919 $array[
'nb_item']=($this->
nb > count($a_item))?$this->
nb:count($a_item);
3920 for ($i=0;$i<count($a_item);$i++)
3922 $array[
'e_march'.$i]=$a_item[$i][
'j_qcode'];
3923 $array[
'e_march'.$i.
'_label']=$a_item[$i][
'ad_text'];
3924 $array[
'e_march'.$i.
'_price']=$a_item[$i][
'ad_pu'];
3925 $array[
'e_march'.$i.
'_tva_id']=$a_item[$i][
'ad_tva_id'];
3926 $array[
'e_march'.$i.
'_tva_amount']=$a_item[$i][
'ad_tva_amount'];
3927 $array[
'e_quant'.$i]=$a_item[$i][
'ad_quant'];
3940 $lib=$this->
db->get_value(
'select pcm_lib from tmp_pcmn where pcm_val=$1',array($p_value));
3955 $r=(
$p_readonly==
false)?
'<div id="repo_div_id" style="height:185px;height:10rem;">':
'<div id="repo_div_id" >';
3957 if ($g_parameter->MY_STOCK==
'Y')
3962 $sel->selected=$p_repo;
3963 $r.=
"<p class=\"decale\">"._(
'Dans le dépôt').
" : ";
3968 $r.=
'<span class="notice">'.
'Stock non utilisé'.
'</span>';
3982 return '<p>'.$button.
'</p>';
3990 echo
'<FORM METHOD="POST">';
3992 array(
"gDossier",
"ac",
"p_jrn",
"e_client",
"nb_item",
"desc",
"e_comm")
3997 for ( $i=0;$i<
$nb;$i++)
4002 "e_march".$i.
"_price",
4003 "e_march".$i.
"_quant",
4004 "e_march".$i.
"_label",
4005 "e_march".$i.
"_tva_id",
4006 "e_march".$i.
"_tva_amount",
get_name()
Return the name of a ledger.
alert($p_msg, $buffer=false)
alert in javascript
get_supplier_late()
get info from supplier not yet paid
get_last_date()
get the date of the last operation
Generate the form for the periode Data Members.
select_depot($p_readonly, $p_repo)
Let you select the repository before confirming a sale or a purchase.
list_operation($sql, $offset, $p_paid=0)
Show all the operation.
static fetch_all($ret)
wrapper for the function pg_fetch_all
get_tiers_id($p_jrn_type, $jr_id)
Return the f_id of the tiers , called by get_tiers.
if($g_user->check_dossier(dossier::id(), true)=='X') $op
this class is used to show the form for entering an operation only FOR analytic operation to save it...
get_propertie()
Get the properties of a journal.
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
delete_ledger()
delete a ledger IF is not already used cannot delete
sql_string($p_string)
Fix the problem with the quote char for the database.
nb($p_number)
format the number for the CSV export
td($p_string='', $p_extra='')
surround the string with td
vat_operation($p_jr_id)
get the amount of vat for a given jr_grpt_id from the table quant_purchase
static num_row($ret)
wrapper for the function pg_NumRows
Class Document corresponds to the table document.
const FICHE_TYPE_FOURNISSEUR
listing()
listing of all ledgers
Manage the account from the table tmp_pcmn.
h2($p_string, $p_class="", $raw="")
th($p_string, $p_extra='', $raw='')
show a button, for selecting a account and a input text for manually inserting an account the differe...
get_class_def()
retrieve the jrn_def_class_deb and return it
button_new_operation()
Create a button to encode a new operation into the same ledger.
nbm($p_number, $p_dec=2)
format the number with a sep.
get_rowSimple($p_from, $p_to, $trunc=0, $p_limit=-1, $p_offset=-1)
Get simplified row from ledger.
get_supplier_now()
get info from supplier to pay today
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
Data & function about connected users.
get_default_card($p_ledger_type, $p_side)
Return an array of default card for the ledger type given.
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
for($i=0;$i< count($a);$i++)
manage the predefined operation, link to the table op_def and op_def_detail
display_ledger()
display detail of a ledger
convert_from_follow($p_ag_id)
Concerns the Analytic plan (table plan_analytique)
get_operation_date($p_date, $p_ledger_type, $sql_op)
Get operation from the ledger type before, after or with the given date .
Manage the account from the table jrn, jrnx or tmp_pcmn.
list_operation_to_reconcile($sql, $p_target)
Show all the operation.
get_type()
Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
input_new()
display screen to enter a new ledger
verify($p_array)
verify that the operation can be saved
get_first($p_type, $p_access=3)
get the first ledger
__construct($p_cn, $p_id)
toNumber($p_num)
remove the useless space, change comma by period and try to return a number
foreach($array as $idx=> $m) $w
reverse($p_date)
reverse the operation by creating the opposite one, the result is to avoid it it must be done in ...
CleanUrl()
Clean the url, remove the $_GET offset,step, page and size.
static escape_string($p_string)
wrapper for the function pg_escape_string
update_internal_code($p_internal)
$def
show a form for quick_writing
update_paid($p_array)
Update the paiment in the list of operation.
get_customer_late()
get info from customer not yet paid
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value...
display_warning($pa_msg, $p_warning)
Display warning contained in an array.
guess_pj()
guess what the next pj should be
get_detail(&$p_array, $p_jrn_type, $trunc=0, $a_TVA=null, $a_ParmCode=null)
get_detail gives the detail of row this array must contains at least the field
search_group($p_what, $p_value)
retreive the jr_grpt_id from a ledger
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
get_operation($p_from, $p_to)
retrieve operation from jrn
select_ledger($p_type="ALL", $p_access=3)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
get_other_amount($p_jr_id)
get the amount of vat for a given jr_grpt_id from the table quant_purchase
get_all_fiche_def()
retrieve all the card for this type of ledger, make them into a string separated by comma ...
save_new($array)
Insert a new ledger.
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
check_strict()
Check if a Dossier is using the strict mode or not.
For the periode tables parm_periode and jrn_periode.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
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.
get_row($p_from, $p_to, $p_limit=-1, $p_offset=-1)
Get The data.
const SQL_LIST_UNPAID_INVOICE
previous_amount($p_to)
retrieve amount of previous periode
get_last($p_limit)
return the last p_limit operation into an array
update($array= '')
update a ledger
for($i=0;$i<$nb_jrn;$i++) $deb
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object ...
global $g_user
Find the default module or the first one.
Class for jrn, class acc_ledger for manipulating the ledger.
$type
type of the ledger ACH ODS FIN VEN or GL
search_form($p_type, $all_type_ledger=1, $div="")
return a HTML string with the form for the search
verify_ledger($array)
Verify before update.
function trim(s)
remove trailing and heading space
new class for managing the reconciliation it must be used instead of the function InsertRapt...
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
get_tiers($p_jrn_type, $jr_id)
Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
GetDefLine()
Get the number of lines of a journal.
build_search_sql($p_array, $p_order="", $p_where="")
this function will create a sql stmt to use to create the list for the ledger,
static id()
return the $_REQUEST['gDossier'] after a check
static array_cat()
create an array of the existing cat, to be used in a checkbox form
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
This class allow you to connect to the postgresql database, execute sql, retrieve data...
get_solde($p_from, $p_to)
get the saldo of a ledger for a specific period
Description of class_syn_sort_table.
save($p_array=null)
save the operation into the jrnx,jrn, , CA and pre_def
get_customer_now()
get info from customer to pay today
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
button_copy_operation()
Show a button to create an operation identical to the recorded one.
get_saldo_exercice($p_exercice)
get the saldo of an exercice, used for the opening of a folder
$nb
default number of rows by default 10
tr($p_string, $p_extra='')
input($p_array=null, $p_readonly=0)
Show the form to encode your operation.
Handle the table mod_payment.
fiche_def_ref, a fiche is owned by fiche_def which is owned by fiche_def_ref
if(!isset($_GET['submit_query'])) $p_action
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
concerns the predefined operation for the operation from 'Ecriture direct'
get_request()
get all the data from request and build the object
static test_me($pCase= '')
this function is intended to test this class
html_page_start($p_theme="", $p_script="", $p_script2="")
Default page header for each page.
get_fiche_def()
retrieve the jrn_def_fiche and return them into a array index deb, cred
inc_seq_pj()
increment the sequence for the pj
this object handles the table quant_sold
static next_number($p_cn, $p_type)
retrieve the next number for this type of ledger
if(isset($_REQUEST['gDossier'])&&$_REQUEST['gDossier']<>0) $repo
confirm($p_array, $p_readonly=false)
show the result of the array to confirm before inserting
existing_vat()
return the used VAT code with a rate > 0
for($e=0;$e< count($afiche);$e++) exit
$name
jrn_def.jrn_def_name
display_search_form()
return a html string with the search_form
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...
find_label($p_value)
Retrieve the label of an accounting.