25 require_once NOALYSS_INCLUDE.
'/lib/class_iselect.php';
26 require_once NOALYSS_INCLUDE.
'/lib/class_icard.php';
27 require_once NOALYSS_INCLUDE.
'/lib/class_ispan.php';
28 require_once NOALYSS_INCLUDE.
'/lib/class_ihidden.php';
29 require_once NOALYSS_INCLUDE.
'/lib/class_iperiod.php';
30 require_once NOALYSS_INCLUDE.
'/lib/class_idate.php';
31 require_once NOALYSS_INCLUDE.
'/lib/class_itext.php';
32 require_once NOALYSS_INCLUDE.
'/lib/class_ifile.php';
33 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger.php';
34 require_once NOALYSS_INCLUDE.
'/class/class_acc_compute.php';
35 require_once NOALYSS_INCLUDE.
'/class/class_anc_operation.php';
36 require_once NOALYSS_INCLUDE.
'/lib/user_common.php';
37 require_once NOALYSS_INCLUDE.
'/class/class_acc_parm_code.php';
38 require_once NOALYSS_INCLUDE.
'/class/class_acc_payment.php';
39 require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
40 require_once NOALYSS_INCLUDE.
'/lib/class_itva_popup.php';
41 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger_info.php';
42 require_once NOALYSS_INCLUDE.
'/class/class_acc_ledger_fin.php';
43 require_once NOALYSS_INCLUDE.
'/class/class_stock_goods.php';
54 parent::__construct($p_cn,$p_init);
66 throw new Exception (
"Array empty");
74 if ( $g_user->check_jrn(
$p_jrn) !=
'W' )
75 throw new Exception (_(
'Accès interdit'),20);
79 if ( isset($mt) && $this->
db->count_sql(
'select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
80 throw new Exception (_(
'Double Encodage'),5);
83 if ( strlen(
trim($e_client)) == 0 )
84 throw new Exception(_(
'Vous n\'avez pas donné de fournisseur'),11);
87 if (
isDate($e_date) == null )
89 throw new Exception(_(
'Date invalide'), 2);
94 $tperiode=
$oPeriode->find_periode($e_date);
104 throw new Exception(_(
'Date et periode ne correspondent pas'),6);
109 throw new Exception(_(
'Periode fermee'),6);
118 if ( $last_date != null &&
cmpDate($e_date,$last_date) < 0 )
119 throw new Exception(_(
'Vous utilisez le mode strict la dernière operation est à la date du ')
120 .$last_date._(
' vous ne pouvez pas encoder à une '.
121 ' date antérieure dans ce journal'),13);
127 $fiche->get_by_qcode($e_client);
130 throw new Exception(_(
'La fiche ').$e_client._(
'n\'a pas de poste comptable'),8);
135 if ( strpos($sposte,
',') != 0 )
137 $array=explode(
',',$sposte);
149 throw new Exception(_(
'Pour la fiche ').$e_client._(
' le poste comptable [').$poste->id.
'] '._(
'n\'existe pas'),9);
153 $fiche->get_by_qcode($e_client,
'cred');
155 throw new Exception(_(
'La fiche ').$e_client._(
'n\'est pas accessible à ce journal'),10);
161 if ($e_mp != 0 ) $this->
check_payment($e_mp,${
"e_mp_qcode_".$e_mp});
167 for ($i=0;$i< $nb_item;$i++)
169 if ( strlen(
trim(${
'e_march'.$i}))== 0)
continue;
171 if (
isNumber(${
'e_march'.$i.
'_price'}) == 0 )
172 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'a un montant invalide').
' ['.${
'e_march'.$i}.
']',6);
173 if (
isNumber(${
'e_quant'.$i}) == 0 )
174 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'a une quantité invalide').
' ['.${
'e_quant'.$i}.
']',7);
177 if ( $g_parameter->MY_TVA_USE==
'Y')
179 if (${
'e_march'.$i.
'_tva_id'} == 0 )
180 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'a un code tva invalide').
' ['.${
'e_march'.$i.
'_tva_id'}.
']',13);
182 $tva_rate->set_parameter(
'id',${
'e_march'.$i.
'_tva_id'});
184 if ( $tva_rate->load() != 0 )
185 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'a un code tva invalide').
' ['.${
'e_march'.$i.
'_tva_id'}.
']',13);
189 $a_poste=explode(
',',$tva_rate->tva_poste);
192 $this->
db->get_value(
'select count(*) from tmp_pcmn where pcm_val=$1',array(
$a_poste[0])) == 0 ||
193 $this->
db->get_value(
'select count(*) from tmp_pcmn where pcm_val=$1',array(
$a_poste[1])) == 0 )
194 throw new Exception(_(
" La TVA ".$tva_rate->tva_label.
" utilise des postes comptables inexistants"));
199 $fiche->get_by_qcode(${
'e_march'.$i});
201 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'n\'a pas de poste comptable'),8);
206 if ( strpos($sposte,
',') != 0 )
208 $array=explode(
',',$sposte);
220 throw new Exception(_(
'Pour la fiche ').${
'e_march'.$i}._(
' le poste comptable').
' ['.
$poste->id._(
'n\'existe pas'),9);
224 $fiche->get_by_qcode(${
'e_march'.$i});
226 throw new Exception(_(
'La fiche ').${
'e_march'.$i}._(
'n\'est pas accessible à ce journal'),10);
243 if ( $this->
db->count_sql(
'select pcm_val from tmp_pcmn where pcm_val=$1',array(
$a->p_value))==0)
244 throw new Exception (
$key[1]._(
"ce code n'a pas de poste comptable, créez ce poste : [".
$a->p_value.
"]"));
252 if ( $poste_nd->load() ==
false)
254 $nd_msg=sprintf(_(
"Pour la fiche %s, le compte contrepartie %s n'existe pas"),
255 $fiche->getName(),$poste_nd->id);
257 throw new Exception ($nd_msg);
266 throw new Exception(_(
'Il n\'y a aucune marchandise'),12);
318 if ($p_acc_operation->jrnx_id == 0) {
319 throw new Exception(__FILE__.__LINE__.
'invalid acc_operation.j_id');
321 $source_j_id=$p_acc_operation->jrnx_id ;
326 if ($p_nd_amount->amount_nd_rate != 0)
336 $dna = $dna_default->p_value;
338 $dna = ($dna ==
'') ? $dna_default->p_value : $dna;
340 $p_acc_operation->type =
'd';
341 $p_acc_operation->amount = $p_nd_amount->amount_nd;
342 $p_acc_operation->poste = $dna;
343 $p_acc_operation->qcode =
'';
345 if ($p_nd_amount->amount_nd > 0)
346 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
352 if ($p_nd_amount->amount_perso != 0)
357 $p_acc_operation->type =
'd';
363 $dna = $dna_default->p_value;
365 $dna = ($dna ==
'') ? $dna_default->p_value : $dna;
367 $p_acc_operation->amount = $p_nd_amount->amount_perso ;
368 $p_acc_operation->poste = $dna;
369 $p_acc_operation->qcode =
'';
371 if ($p_nd_amount->amount_perso> 0)
372 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
375 if ($p_nd_amount->nd_vat != 0)
380 $p_acc_operation->type =
'd';
381 $p_acc_operation->qcode =
'';
387 $dna = $dna_default->p_value;
389 $dna = ($dna ==
'') ? $dna_default->p_value : $dna;
391 $p_acc_operation->amount = $p_nd_amount->nd_vat;
392 $p_acc_operation->poste = $dna;
395 if ( $g_parameter->MY_ANALYTIC !=
"nu" )
398 $op->oa_group=$p_group;
400 $op->oa_date=$p_acc_operation->date;
404 $op->oa_jrnx_id_source=$source_j_id;
405 $op->save_form_plan_vat_nd(
$_POST,
$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
407 if ($p_nd_amount->nd_vat> 0)
408 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
411 if ($p_nd_amount->nd_ded_vat != 0)
420 $dna = $dna_default->p_value;
422 $dna = ($dna ==
'') ? $dna_default->value : $dna;
426 $p_acc_operation->type =
'd';
427 $p_acc_operation->qcode =
'';
428 $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
429 $p_acc_operation->poste = $dna;
431 if ($p_nd_amount->nd_ded_vat > 0)
432 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
434 if ( $g_parameter->MY_ANALYTIC !=
"nu" )
437 $op->oa_group=$p_group;
439 $op->oa_date=$p_acc_operation->date;
443 $op->oa_jrnx_id_source=$source_j_id;
444 $op->save_form_plan_vat_nd(
$_POST,
$idx,$j_id,$p_nd_amount->nd_ded_vat);
490 $group=$this->
db->get_next_seq(
"s_oa_group");
491 $seq=$this->
db->get_next_seq(
's_grpt');
495 $this->
internal=$internal;
498 $cust->get_by_qcode($e_client);
501 if ( strpos($sposte,
',') != 0 )
503 $array=explode(
',',$sposte);
517 $tperiode=
$oPeriode->find_periode($e_date);
534 for ($i=0;$i< $nb_item;$i++)
537 if ( strlen(
trim(${
'e_march'.$i})) == 0 )
continue;
541 $fiche->get_by_qcode(${
"e_march".$i});
544 if ($g_parameter->MY_TVA_USE==
'Y')
546 $idx_tva=${
'e_march'.$i.
'_tva_id'};
548 $oTva->set_parameter(
'id',$idx_tva);
550 $tva_both=$oTva->get_parameter(
"both_side");
554 $acc_operation->date=$e_date;
555 $acc_operation->grpt=
$seq;
556 $acc_operation->jrn=
$p_jrn;
557 $acc_operation->type=
'd';
558 $acc_operation->periode=$tperiode;
559 $acc_operation->qcode=
"";
560 $amount_4=bcmul(${
'e_march'.$i.
'_price'},${
'e_quant'.$i});
565 $acc_amount->check=
false;
566 $acc_amount->set_parameter(
'amount',$amount);
569 if ( $g_parameter->MY_TVA_USE==
'Y')
571 $acc_amount->set_parameter(
'amount_vat_rate',$oTva->get_parameter(
'rate'));
572 if ( strlen(
trim(${
'e_march'.$i.
'_tva_amount'})) ==0 || ${
'e_march'.$i.
'_tva_amount'} == 0)
574 $acc_amount->compute_vat();
579 $acc_amount->amount_vat= ${
'e_march'.$i.
'_tva_amount'};
582 $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
587 $save_amount_vat=$acc_amount->amount_vat;
589 $acc_amount->correct();
591 $acc_amount->amount_unpaid=($tva_both == 1 ) ? $save_amount_vat :0 ;
592 $tot_tva_reversed=bcadd($tot_tva_reversed,$acc_amount->amount_unpaid);
596 $tot_amount=round(bcadd($tot_amount,$amount),2);
601 if ( strpos($sposte,
',') != 0 )
603 $array=explode(
',',$sposte);
610 if ( $g_parameter->MY_UPDLAB==
'Y')
611 $acc_operation->desc=strip_tags(${
"e_march".$i.
"_label"});
613 $acc_operation->desc=null;
614 $acc_operation->poste=$poste_val;
615 $acc_operation->amount=$acc_amount->amount;
616 $acc_operation->qcode=${
"e_march".$i};
617 if( $acc_amount->amount > 0 ) $tot_debit=bcadd($tot_debit,$acc_amount->amount);
618 $j_id=$acc_operation->insert_jrnx();
625 if ( $g_parameter->MY_TVA_USE==
'Y')
627 $tva_item=$acc_amount->amount_vat;
629 if (isset($tva[$idx_tva] ) )
630 $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item);
632 $tva[$idx_tva]=$tva_item;
639 $nNeg=(${
"e_quant" . $i}< 0) ? -1 : 1;
643 if ( $g_parameter->MY_STOCK=
'Y'&& isset (
$repo))
645 $dir=(${
'e_quant'.$i} < 0 ) ?
'c':
'd';
649 if ( $g_parameter->MY_ANALYTIC !=
"nu" )
653 $op->oa_group=$group;
655 $op->oa_date=$e_date;
662 if ( $g_parameter->MY_TVA_USE==
'Y')
665 $r=$this->
db->exec_sql(
"select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
672 ,$acc_amount->amount_vat
673 ,$oTva->get_parameter(
'id')
674 ,$acc_amount->amount_nd
676 ,$acc_amount->nd_ded_vat
677 ,$acc_amount->amount_perso
679 , $acc_amount->amount_unpaid
680 ,${
'e_march'.$i.
'_price'}
687 $r=$this->
db->exec_sql(
"select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
696 ,$acc_amount->amount_nd
698 ,$acc_amount->nd_ded_vat
699 ,$acc_amount->amount_perso
701 , $acc_amount->amount_unpaid
702 ,${
'e_march'.$i.
'_price'}
708 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
710 $acc_operation->date=$e_date;
711 $acc_operation->poste=
$poste;
712 $acc_operation->amount=bcsub($cust_amount,$tot_tva_reversed);
713 $acc_operation->grpt=
$seq;
714 $acc_operation->jrn=
$p_jrn;
715 $acc_operation->type=
'c';
716 $acc_operation->periode=$tperiode;
717 $acc_operation->qcode=${
"e_client"};
718 if ( $cust_amount < 0 )
719 $tot_debit=bcadd($tot_debit,abs($cust_amount));
720 $let_client=$acc_operation->insert_jrnx();
723 if ( $g_parameter->MY_TVA_USE==
'Y')
728 foreach ($tva as $i =>
$value)
731 $oTva->set_parameter(
'id',$i);
734 $poste_vat=$oTva->get_side(
'd');
736 $cust_amount=bcadd($tot_amount,$tot_tva);
738 $acc_operation->date=$e_date;
739 $acc_operation->poste=$poste_vat;
740 $acc_operation->amount=
$value;
741 $acc_operation->grpt=
$seq;
742 $acc_operation->jrn=
$p_jrn;
743 $acc_operation->type=
'd';
744 $acc_operation->periode=$tperiode;
745 if (
$value > 0 ) $tot_debit=bcadd($tot_debit,abs(
$value));
746 $acc_operation->insert_jrnx();
748 if ( $oTva->get_parameter(
"both_side")==1)
750 $poste_vat=$oTva->get_side(
'c');
753 $acc_operation->date=$e_date;
754 $acc_operation->poste=$poste_vat;
755 $acc_operation->amount=$tot_tva_reversed;
756 $acc_operation->grpt=
$seq;
757 $acc_operation->jrn=
$p_jrn;
758 $acc_operation->type=
'c';
759 $acc_operation->periode=$tperiode;
760 $acc_operation->insert_jrnx();
761 if (
$value < 0 ) $tot_debit=bcadd($tot_debit,abs(
$value));
768 $acc_operation->date=$e_date;
769 $acc_operation->echeance=$e_ech;
771 $acc_operation->amount=$this->
db->get_value(
"select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
773 $acc_operation->desc=$e_comm;
774 $acc_operation->grpt=
$seq;
775 $acc_operation->jrn=
$p_jrn;
776 $acc_operation->periode=$tperiode;
777 $acc_operation->pj=$e_pj;
778 $acc_operation->mt=$mt;
779 $this->
jr_id=$acc_operation->insert_jrn();
780 $this->pj=$acc_operation->set_pj();
786 $this->
db->exec_sql(
'update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
787 array($internal,
$seq));
790 if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(
trim($e_pj)) != 0 )
796 if ( isset ($_FILES))
798 if (
sizeof($_FILES) != 0 )
799 $this->
db->save_receipt(
$seq);
804 if ( isset(
$_POST[
'gen_invoice']) )
820 if ($mp->get_parameter(
'qcode') ==
'')
821 $fqcode=${
'e_mp_qcode_'.$e_mp};
823 $fqcode=$mp->get_parameter(
'qcode');
825 $acfiche =
new Fiche($this->
db);
826 $acfiche->get_by_qcode($fqcode);
829 $acseq=$this->
db->get_next_seq(
's_grpt');
830 $acjrn=
new Acc_Ledger($this->
db,$mp->get_parameter(
'ledger_target'));
835 $acc_pay->date=$e_date;
840 if ( strpos($sposte,
',') != 0 )
842 $array=explode(
',',$sposte);
850 $cust_amount=bcsub($cust_amount, $tot_tva_reversed);
851 $famount=bcsub($cust_amount,$acompte);
852 $acc_pay->poste=$poste_val;
853 $acc_pay->qcode=$fqcode;
854 $acc_pay->amount=abs(round($famount,2));
856 $acc_pay->grpt=$acseq;
857 $acc_pay->jrn=$mp->get_parameter(
'ledger_target');
858 $acc_pay->periode=$tperiode;
859 $acc_pay->type=($famount>=0)?
'c':
'd';
860 $acc_pay->insert_jrnx();
864 $acc_pay->date=$e_date;
866 $acc_pay->qcode=$e_client;
867 $acc_pay->amount=abs(round($famount,2));
869 $acc_pay->grpt=$acseq;
870 $acc_pay->jrn=$mp->get_parameter(
'ledger_target');
871 $acc_pay->periode=$tperiode;
872 $acc_pay->type=($famount>=0)?
'd':
'c';
873 $let_other=$acc_pay->insert_jrnx();
877 $acc_pay->desc=(!isset($e_comm_paiement) || strlen(
trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement;
878 $mp_jr_id=$acc_pay->insert_jrn();
879 $acjrn->grpt_id=$acseq;
880 $acjrn->update_internal_code($acinternal);
882 $r1=$this->
get_id($internal);
883 $r2=$this->
get_id($acinternal);
889 $oletter->insert_couple($let_client,$let_other);
892 $Res=$this->
db->exec_sql(
"update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
896 $rec->set_jr_id($r1);
907 if (
$prop[
'jrn_def_type'] ==
'FIN' )
909 $ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1));
917 echo
'<span class="error">'.
918 'Erreur dans l\'enregistrement '.
919 __FILE__.
':'.__LINE__.
' '.
920 $e->getMessage().$e->getMessage();
921 error_log($e->getMessage());
922 $this->
db->rollback();
923 throw new Exception($e);
966 $flag_tva=$g_parameter->MY_TVA_USE;
968 $f_add_button=
new IButton(
'add_card');
969 $f_add_button->label=_(
'Créer une nouvelle fiche');
970 $f_add_button->tabindex=-1;
971 $f_add_button->set_attribute(
'jrn',$this->
id);
972 $f_add_button->javascript=
" this.jrn=\$('p_jrn').value;select_card_type(this);";
975 if ($g_user->check_action(
FICADD)==1)
977 $str_add_button=$f_add_button->input();
981 list ($l_date_start,$l_date_end)=
$oPeriode->get_date_limit($g_user->get_periode());
982 if ( $g_parameter->MY_DATE_SUGGEST==
'Y' )
983 $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
985 $op_date=( ! isset($e_date) ) ?
'':$e_date;
987 $e_ech=(isset($e_ech))?$e_ech:
"";
988 $e_comm=(isset($e_comm))?$e_comm:
"";
991 $r.=dossier::hidden();
992 $f_legend_detail=_(
"Détail articles achetés");
997 $Date->setReadOnly(
false);
1000 $f_date=$Date->input(
"e_date",$op_date);
1003 $Echeance=
new IDate();
1004 $Echeance->setReadOnly(
false);
1005 $Echeance->tabindex=2;
1007 $f_echeance=$Echeance->input(
'e_ech',$e_ech,
'Echéance'.
$label);
1013 $l_user_per=$g_user->get_periode();
1016 $period=
new IPeriod(
"period");
1019 $period->value=
$def;
1023 $l_form_per=$period->input();
1025 catch (Exception
$e)
1027 if ($e->getCode() == 1 )
1029 throw new Exception( _(
"Aucune période ouverte"));
1035 $f_periode=
td(_(
"Période comptable").
" $label ").td($l_form_per);
1041 if ( $g_parameter->MY_PJ_SUGGEST==
'Y')
1043 $add_js=
"update_pj();";
1045 if ($g_parameter->MY_DATE_SUGGEST ==
'Y')
1047 $add_js.=
'get_last_date();';
1049 $add_js.=
'update_name();';
1050 $add_js.=
'update_pay_method();';
1051 $add_js.=
'update_row("sold_item");';
1055 if (
$wLedger == null)
throw new Exception(_(
'Pas de journal disponible'));
1056 $wLedger->javascript=
"onChange='update_predef(\"ach\",\"f\",\"".$_REQUEST[
'ac'].
"\");$add_js'";
1062 $Commentaire=
new IText();
1063 $Commentaire->table=0;
1064 $Commentaire->setReadOnly(
false);
1065 $Commentaire->size=60;
1066 $Commentaire->tabindex=3;
1068 $f_desc=$Commentaire->input(
"e_comm",
h($e_comm));
1074 if ( $g_parameter->MY_PJ_SUGGEST==
'Y')
1080 $pj->value=(isset($e_pj))?$e_pj:$default_pj;
1086 $pj->readonly=
false;
1088 $f_pj=$pj->input().HtmlInput::hidden(
'e_pj_suggest',$default_pj);
1096 $e_client=( isset ($e_client) )?$e_client:
"";
1097 $e_client_label=
" ";
1103 if ( strlen(
trim($e_client)) != 0)
1105 $fClient=
new Fiche($this->
db);
1106 $fClient->get_by_qcode($e_client);
1116 $W1->label=_(
"Fournisseur ").HtmlInput::infobulle(0) ;
1117 $W1->name=
"e_client";
1119 $W1->value=$e_client;
1121 $W1->set_dblclick(
"fill_ipopcard(this);");
1122 $W1->set_attribute(
'ipopup',
'ipopcard');
1125 $W1->set_attribute(
'label',
'e_client_label');
1127 $W1->set_attribute(
'typecard',
'cred');
1130 $W1->set_callback(
'filter_card');
1131 $W1->set_function(
'fill_data');
1132 $W1->javascript=sprintf(
' onchange="fill_data_onchange(\'%s\');" ',
1134 $f_client_qcode=$W1->input();
1135 $client_label=
new ISpan();
1136 $client_label->table=0;
1137 $f_client=$client_label->input(
"e_client_label",$e_client_label);
1138 $f_client_bt=$W1->search();
1143 $e_comment=(isset($e_comment))?$e_comment:
"";
1144 $p_article= ( isset ($nb_item))?$nb_item:$this->
get_min_row();
1148 $r.=$Hid->input(
"nb_item",$p_article);
1152 for ($i=0;$i< $p_article ;$i++)
1156 $march=(isset(${
"e_march$i"}))?${
"e_march$i"}:
"" ;
1157 $march_price=(isset(${
"e_march".$i.
"_price"}))?${
"e_march".$i.
"_price"}:
""
1160 if ( $g_parameter->MY_TVA_USE==
'Y')
1162 $march_tva_id=(isset(${
"e_march$i".
"_tva_id"}))?${
"e_march$i".
"_tva_id"}:
"";
1163 $march_tva_amount=(isset(${
"e_march$i".
"_tva_amount"}))?${
"e_march$i".
"_tva_amount"}:
"";
1168 $march_label=(isset(${
"e_march".$i.
"_label"}))?${
"e_march".$i.
"_label"}:
"";
1171 if ( strlen(
trim($march))!=0 && strlen(
trim($march_label))==0 )
1174 $fMarch->get_by_qcode($march);
1177 if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE==
'Y' )
1184 $W1->name=
"e_march".$i;
1187 $W1->set_dblclick(
"fill_ipopcard(this);");
1188 $W1->set_attribute(
'ipopup',
'ipopcard');
1190 $W1->set_attribute(
'typecard',
'deb');
1193 $W1->set_attribute(
'label',
'e_march'.$i.
'_label');
1195 $W1->set_attribute(
'purchase',
'e_march'.$i.
'_price');
1196 $W1->set_attribute(
'price',
'e_march'.$i.
'_price');
1199 $W1->set_attribute(
'tvaid',
'e_march'.$i.
'_tva_id');
1201 $W1->set_callback(
'filter_card');
1202 $W1->set_function(
'fill_data');
1203 $W1->javascript=sprintf(
' onchange="fill_data_onchange(\'%s\');" ',
1205 $W1->readonly=
false;
1206 $array[$i][
'quick_code']=$W1->input();
1207 $array[$i][
'bt']=$W1->search();
1211 if ( $g_parameter->MY_TVA_USE==
'Y')
1216 if ( $g_parameter->MY_TVA_USE==
'Y')
1217 $tvac=
new INum(
'tvac_march'.$i);
1219 $tvac=
new IHidden(
'tvac_march'.$i);
1223 $array[$i][
'tvac']=$tvac->input();
1225 $htva=
new INum(
'htva_march'.$i);
1229 $array[$i][
'htva']=$htva->input();
1231 if ( $g_parameter->MY_UPDLAB ==
'Y')
1233 $Span=
new IText(
"e_march".$i.
"_label");
1234 $Span->css_size=
"100%";
1237 $Span=
new ISpan(
"e_march".$i.
"_label");
1239 $Span->value=$march_label;
1240 $Span->setReadOnly(
false);
1243 $array[$i][
'denom']=$Span->input(
"e_march".$i.
"_label",$march_label);
1246 $Price->setReadOnly(
false);
1248 $Price->javascript=
"onBlur='format_number(this,4);clean_tva($i);compute_ledger($i)'";
1249 $array[$i][
'pu']=$Price->input(
"e_march".$i.
"_price",$march_price);
1250 if ( $g_parameter->MY_TVA_USE==
'Y')
1256 $Tva->js=
"onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
1257 $Tva->in_table=
true;
1258 $Tva->set_attribute(
'compute',$i);
1259 $Tva->value=$march_tva_id;
1260 $array[$i][
'tva']=$Tva->input(
"e_march$i".
"_tva_id");
1265 $Tva_amount=
new INum();
1266 $Tva_amount->setReadOnly(
false);
1267 $Tva_amount->size=9;
1268 $Tva_amount->javascript=
"onBlur='format_number(this);compute_ledger($i)'";
1269 $array[$i][
'amount_tva']=$Tva_amount->input(
"e_march".$i.
"_tva_amount",$march_tva_amount);
1273 $quant=(isset(${
"e_quant$i"}))?${
"e_quant$i"}:
"1"
1275 $Quantity=
new INum();
1276 $Quantity->setReadOnly(
false);
1278 $Quantity->javascript=
"onChange=format_number(this);clean_tva($i);compute_ledger($i)";
1279 $array[$i][
'quantity']=$Quantity->input(
"e_quant".$i,$quant);
1282 $f_type=_(
'Fournisseur');
1285 require_once NOALYSS_TEMPLATE.
'/form_ledger_detail.php';
1286 $r.=ob_get_contents();
1296 if ( $g_parameter->MY_PJ_SUGGEST==
'Y')
1298 $r.=
'<script> update_pj();</script>';
1326 $client->get_by_qcode($e_client,
true);
1328 $client_name=
h($client->getName().
1335 $lPeriode->p_id=$period;
1339 $lPeriode->find_periode($e_date);
1343 $r .=
'<div id="summary_op1">';
1346 $jr_id=$this->
db->get_value(
'select jr_id from jrn where jr_internal=$1',array($this->
internal));
1349 $r.=_(
'Détail opération ');
1352 $r.=sprintf (
'<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
1358 if ( ! $p_summary) {
1359 $r.=
'<td>' . _(
'Numéro Pièce') .
'</td><td>'.
hb($e_pj) .
'</td>';
1362 if ( strcmp($this->pj,$e_pj) != 0 )
1364 $r.=
'<td>' . _(
'Numéro Pièce') .
'</td><td>'.
hb($this->pj) .
1365 '<span class="notice"> '._(
'Attention numéro pièce existante, elle a du être adaptée').
'</span></td>';
1367 $r.=
'<td>' . _(
'Numéro Pièce') .
'</td><td>'.
hb($this->pj) .
'</td>';
1371 $r.=
'<td> ' . _(
'Date') .
'</td><td> ' .
hb($e_date) .
'</td>';
1374 $r.=
'<td>' . _(
'Echeance') .
'</td><td> ' .
hb($e_ech) .
'</td>';
1379 $r.=
'<td> ' . _(
'Période Comptable') .
'</td><td> ' .hb(
$date_limit[
'p_start'] .
'-' .
$date_limit[
'p_end']) .
'</td>';
1383 $r .=
'<div id="summary_op2">';
1386 $r.=
'<td> ' . _(
'Journal') .
'</td><td> ' .
hb($this->
get_name()) .
'</td>';
1389 $r.=
'<td> ' . _(
'Libellé') .
'</td><td> ' .
hb($e_comm) .
'</td>';
1394 $r.=
'<td> ' . _(
'Fournisseur') .
'</td><td> ' .
hb($e_client .
':' . $client_name) .
'</td>';
1398 $r.=
'<div style="position:float;clear:both">';
1400 $r.=
'<h2>' . _(
'Détail articles achetés') .
'</h2>';
1401 $r.=
'<p class="decale">';
1402 $r.=
'<table class="result" >';
1404 $r.=
"<th>" . _(
'Code') .
"</th>";
1405 $r.=
"<th>" . _(
'Dénomination') .
"</th>";
1406 $r.=
"<th style=\"text-align:right\">" . _(
'prix') .
"</th>";
1407 $r.=
"<th style=\"text-align:right\">" . _(
'quantité') .
"</th>";
1410 if ($g_parameter->MY_TVA_USE ==
'Y') {
1411 $r.=
"<th style=\"text-align:right\">" . _(
'tva') .
"</th>";
1412 $r.=
'<th style="text-align:right"> ' . _(
'Montant TVA') .
'</th>';
1413 $r.=
'<th style="text-align:right">' . _(
'Montant HTVA') .
'</th>';
1414 $r.=
'<th style="text-align:right">' . _(
'Montant TVAC') .
'</th>';
1416 $r.=
'<th style="text-align:right">' . _(
'Montant') .
'</th>';
1420 if ($g_parameter->MY_ANALYTIC!=
'nu')
1423 $a_anc=
$anc->get_list();
1426 $r.=
'<th colspan="'.$x.
'">'._(
'Compt. Analytique').
'</th>';
1438 for ($i = 0; $i < $nb_item;$i++)
1441 if ( strlen(
trim(${
"e_march".$i})) == 0 )
continue;
1445 $fiche->get_by_qcode(${
"e_march".$i});
1446 if ( $g_parameter->MY_UPDLAB==
'Y')
1447 $fiche_name=
h(${
"e_march".$i.
"_label"});
1450 $amount=bcmul(${
"e_march".$i.
"_price"},${
'e_quant'.$i});
1451 if ( $g_parameter->MY_TVA_USE==
'Y')
1453 $idx_tva=${
"e_march".$i.
"_tva_id"};
1455 $oTva->set_parameter(
'id',$idx_tva);
1460 $op->set_parameter(
'amount_vat_rate',$oTva->get_parameter(
'rate'));
1462 $tva_computed=
$op->get_parameter(
'amount_vat');
1464 if ( strlen (
trim (${
'e_march'.$i.
'_tva_amount'})) == 0)
1466 $tva_item=
$op->get_parameter(
'amount_vat');
1469 $tva_item=round(${
'e_march'.$i.
'_tva_amount'},2);
1471 if (isset($tva[$idx_tva] ) )
1472 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
1474 $tva[$idx_tva]=$tva_item;
1479 $tot_amount=round(bcadd($tot_amount,
$amount),2);
1480 $tot_row=round(bcadd($tot_row,
$amount),2);
1483 $r.=${
"e_march".$i};
1485 $r.=
'<TD style="border-bottom:1px dotted grey;">';
1488 $r.=
'<td class="num">';
1489 $r.=
nbm(${
"e_march".$i.
"_price"},4);
1491 $r.=
'<td class="num">';
1492 $r.=
nbm(${
"e_quant".$i});
1495 if ($g_parameter->MY_TVA_USE ==
'Y')
1497 $r.=
'<td class="num">';
1498 $r.=$oTva->get_parameter(
'label');
1499 $both_side=$oTva->get_parameter(
"both_side");
1501 $tot_row=bcadd($tot_row,$tva_item);
1502 $tot_tva=round(bcadd($tva_item,$tot_tva),2);
1507 $css_void_tva=(
$both_side == 1)?
'style="text-decoration:line-through"':
'';
1508 if ( bcsub($tva_item,$tva_computed) != 0 && ! ($tva_item == 0 &&
$both_side == 1))
1511 $r.=
'<td style="background-color:red" class="num" '.$css_void_tva.
'>';
1513 $r.=
'<a href="#" class="error" style="display:inline" title="'. _(
"Attention Différence entre TVA calculée et donnée").
'">'
1514 .nbm($tva_item).
'<a>';
1517 $r.=
'<td class="num" '.$css_void_tva.
'>';
1521 $r.=
'<td class="num"> ';
1525 $r.=
'<td class="num">';
1526 $r.=
nbm(round($tot_row,2));
1529 if ( $g_parameter->MY_ANALYTIC!=
'nu')
1533 $null=($g_parameter->MY_ANALYTIC==
'op')?1:0;
1535 $p_mode=($p_summary==
false)?1:0;
1548 $decalage=($g_parameter->MY_TVA_USE ==
'Y')?
'<td></td><td></td><td></td><td></td>':
'<td></td>';
1549 $tot = round(bcadd($tot_amount, $tot_tva), 2);
1550 $tot_tva=
nbm($tot_tva);
1552 $str_tot=_(
'Totaux');
1553 $tot_amount=
nbm($tot_amount);
1555 <
tr class=
"highlight">
1573 if ( $g_parameter->MY_ANALYTIC!=
'nu' && !$p_summary)
1574 $r.=
'<input type="button" class="button" value="'._(
'Vérifiez imputation analytique').
'" onClick="verify_ca(\'\');">';
1576 $r.=(! $p_summary )?
'<div id="total_div_id" >':
'<div>';
1577 $r.=
'<h2>Totaux</h2>';
1579 if ($g_parameter->MY_TVA_USE ==
'Y') {
1581 $r.=
'<tr><td>Total HTVA</td>';
1582 $r.=
td(
hb($tot_amount ),
'class="num"');
1583 foreach ($tva as $i =>
$value) {
1584 $oTva->set_parameter(
'id', $i);
1587 $r.=
'<tr><td> TVA ' . $oTva->get_parameter(
'label').
'</td>';
1588 $r.=
td(
hb(
nbm($tva[$i])),
'class="num"');
1590 $r.=
'<tr>'.td(_(
'Total TVA')).td(
hb($tot_tva),
'class="num"');
1591 $r.=
'<tr>'.td(_(
'Total TVAC')).td(
hb(
$tot),
'class="num"');
1594 $r.=
'<br>Total '.hb(
$tot);
1601 if ( isset($period))
1609 $mt=microtime(
true);
1612 $e_mp=(isset($e_mp))?$e_mp:0;
1618 for ($i=0;$i < $nb_item;$i++)
1621 if (isset (${
"e_march".$i.
"_label"}))
$r.=
HtmlInput::hidden(
"e_march".$i.
"_label",${
"e_march".$i.
"_label"});
1635 if ( $e_mp!=0 && strlen (
trim (${
'e_mp_qcode_'.$e_mp})) != 0 )
1642 $fname =
new Fiche($this->
db);
1643 $fname->get_by_qcode(${
'e_mp_qcode_' . $e_mp});
1644 $r.=
'<h2>' . _(
"Payé par").
" " . ${
'e_mp_qcode_' . $e_mp} .
1645 " " . $fname->getName() .
'</h2> ' .
'<p class="decale">' . _(
'Déduction acompte ') .
h($acompte) .
'</p>' .
1646 _(
'Libellé :') .
h($e_comm_paiement) ;
1664 $r =
'<div id="facturation_div_id" style="height:185px;height:10rem">';
1665 $r.=
'<p class="decale">';
1669 $r.=_(
"Ajoutez une pièce justificative ");
1672 if ( $this->
db->count_sql(
"select md_id,md_name from document_modele where md_affect='ACH'") > 0 )
1675 $r.=_(
'ou générer un document').
' <input type="checkbox" name="gen_invoice" >';
1678 $doc_gen->name=
"gen_doc";
1679 $doc_gen->value=$this->
db->make_array(
1680 "select md_id,md_name ".
1681 " from document_modele where md_affect='ACH'");
1682 $r.=$doc_gen->input().
'<br>';
1686 $r.=_(
'Numero de bon de commande : ').$obj->input(
'bon_comm').
'<br>';
1687 $r.=_(
'Autre information : ').$obj->input(
'other_info').
'<br>';
1704 $step=$_SESSION[
'g_pagesize'];
1712 list($max_line2,$list2)=$this->list_operation(
$sql,null,
$offset,1);
1719 echo
'<h2 class="info"> '._(
'Echeance dépassée').
' </h2>';
1721 echo
'<h2 class="info"> '._(
'Non Payée').
' </h2>';
1745 if ( $this->
id == 0 ) die (__FILE__.
":".__LINE__.
" Journal invalide");
1748 if ( $g_user->get_ledger_access($this->id) ==
'X' )
return null;
1752 from v_detail_purchase
1755 and jr_date >= (select p_start from parm_periode where p_id = $2)
1756 and jr_date <= (select p_end from parm_periode where p_id = $3) "
1757 .
' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
1758 $ret = $this->
db->exec_sql(
$sql, array($this->
id,$p_from, $p_end));
1768 $array[
'jr_id'] = _(
'Numéro opération');
1769 $array[
'jr_date'] = _(
'Date');
1770 $array[
'jr_date_paid'] = _(
'Date paiement');
1771 $array[
'jr_ech'] = _(
'Date échéance');
1772 $array[
'jr_tech_per'] = _(
'Période');
1773 $array[
'jr_comment'] = _(
'Libellé');
1774 $array[
'jr_pj_number'] = _(
'Pièce');
1775 $array[
'jr_internal'] = _(
'Interne');
1776 $array[
'jr_def_id'] = _(
'Code journal');
1777 $array[
'j_poste'] = _(
'Poste');
1778 $array[
'j_text'] = _(
'Commentaire');
1779 $array[
'j_qcode'] = _(
'Code Item');
1780 $array[
'item_card'] = _(
'N° fiche');
1781 $array[
'item_name'] = _(
'Nom fiche');
1782 $array[
'qp_supplier'] = _(
'N° fiche fournisseur');
1783 $array[
'tiers_name'] = _(
'Nom fournisseur');
1784 $array[
'quick_code'] = _(
'Code fournisseur');
1785 $array[
'tva_label'] = _(
'Nom TVA');
1786 $array[
'tva_comment'] = _(
'Commentaire TVA');
1787 $array[
'tva_both_side'] = _(
'TVA annulée');
1788 $array[
'vat_sided'] = _(
'TVA Non Payé');
1789 $array[
'vat_code'] = _(
'Code TVA');
1790 $array[
'vat'] = _(
'Montant TVA');
1791 $array[
'price'] = _(
'Total HTVA');
1792 $array[
'quantity'] = _(
'quantité');
1793 $array[
'price_per_unit'] = _(
'PU');
1794 $array[
'non_ded_amount'] = _(
'Montant ND');
1795 $array[
'non_ded_tva'] = _(
'Montant TVA ND');
1796 $array[
'non_ded_tva_recup'] = _(
'TVA récup.');
1797 $array[
'htva'] = _(
'HTVA Opération');
1798 $array[
'tot_vat'] = _(
'TVA Opération');
1799 $array[
'tot_tva_np'] = _(
'TVA NP opération');
const ATTR_DEF_ACCOUNT_ND_TVA
get_name()
Return the name of a ledger.
get_last_date()
get the date of the last operation
Generate the form for the periode Data Members.
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...
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
const ATTR_DEF_ACCOUNT_ND_TVA_ND
Manage the table parm_code which contains the custom parameter for the module accountancy.
sql_string($p_string)
Fix the problem with the quote char for the database.
td($p_string='', $p_extra='')
surround the string with td
const ATTR_DEF_ACCOUNT_ND
show_unpaid_deprecated()
update the payment
const SQL_LIST_UNPAID_INVOICE_DATE_LIMIT
verify($p_array)
verify that the data are correct before inserting or confirming
compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
Compute the ND amount thanks the attribute of the concerned card.
nbm($p_number, $p_dec=2)
format the number with a sep.
Handle the ledger of purchase,.
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
Concerns the Analytic plan (table plan_analytique)
Manage the account from the table jrn, jrnx or tmp_pcmn.
input($p_array=null, $p_readonly=0)
display the form for entering data for invoice
update_internal_code($p_internal)
$def
show a form for quick_writing
Acc_Tva is used for to map the table tva_rate parameter are.
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value...
guess_pj()
guess what the next pj should be
const ATTR_DEF_DEPENSE_NON_DEDUCTIBLE
select_ledger($p_type="ALL", $p_access=3)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
check_strict()
Check if a Dossier is using the strict mode or not.
insert($p_array=null)
insert into the database, it calls first the verify function change the value of this->jr_id and this-...
confirm($p_array, $p_summary=false)
show the summary of the operation and propose to save it
For the periode tables parm_periode and jrn_periode.
if(isset($_POST['confirm_rm'])) $both_side
is_closed($p_periode)
check if the current ledger is closed
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
const SQL_LIST_UNPAID_INVOICE
insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT...
static heading_detail_purchase()
compute an array with the heading cells for the details, used for the export in CSV ...
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.
empty_attribute($p_attr)
check if an attribute is empty
function trim(s)
remove trailing and heading space
new class for managing the reconciliation it must be used instead of the function InsertRapt...
strAttribut($p_ad_id, $p_return=1)
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
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...
const ATTR_DEF_ACCOUNT_ND_PERSO
const ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
this class aims to compute different amount
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
const ATTR_DEF_TVA_NON_DEDUCTIBLE
$nb
default number of rows by default 10
extra_info()
the function extra info allows to
tr($p_string, $p_extra='')
Handle the table mod_payment.
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
get_detail_purchase($p_from, $p_end)
Retrieve data from the view v_detail_purchase.
__construct($p_cn, $p_init)
inc_seq_pj()
increment the sequence for the pj
insert_jrnx()
Insert into the table Jrn The needed data are :
compute_nd()
Compute the no deductible part of the amount, it reduce also the vat.
if(isset($_REQUEST['gDossier'])&&$_REQUEST['gDossier']<>0) $repo
create_script($p_string)
create the HTML for adding the script tags around of the script
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...
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...