25 require_once
'class_copro_key.php';
26 require_once
'class_copro_budget.php';
32 $array=$cn->get_array(
"SELECT af_id, to_char(af_date,'DD.MM.YYYY') as af_date,
33 af_confirmed, af_percent, af_amount, af_card,
34 af_ledger, tech_per, jr_internal, b_id, cr_id
35 FROM coprop.appel_fond where af_id=$1",
38 $var=array(
'af_id',
'af_date',
'af_confirmed',
'af_percent',
'af_amount',
'af_card',
'af_ledger',
'tech_per',
'jr_internal',
'b_id',
'cr_id');
39 for ($i=0;$i<count(
$array);$i++)
42 $this->$idx=
$array[0][$idx];
52 $this->
id=$cn->get_next_seq(
'coprop.appel_fond_id');
54 $cn->exec_sql(
"delete from coprop.appel_fond where af_confirmed='N' and tech_per < now() - interval '5 hours' ");
57 $cn->exec_sql(
"insert into coprop.appel_fond(af_id,af_date,af_confirmed,af_percent,af_amount,af_card,af_ledger,tech_per,b_id,cr_id)
58 values ($1,to_date($2,'DD.MM.YYYY'),'N',$3,$4,$5,$6,now(),$7,$8)",
59 array($this->
id,$this->af_date,$this->af_percent,$this->af_amount,$this->af_card,$this->af_ledger,$this->
b_id,$this->cr_id));
70 $key->cr_id=$p_key_id;
74 $a_lot=
$key->get_detail();
75 for ($i=0;$i<count($a_lot);$i++)
79 $afd->lot_id=$a_lot[$i][
'lot_fk'];
80 $afd->key_id=$p_key_id;
81 $afd->key_tantieme=
$key->cr_tantieme;
82 $afd->lot_tantieme=$a_lot[$i][
'crd_amount'];
84 $temp= bcmul($a_lot[$i][
'crd_amount'],
$p_amount);
85 $afd->afd_amount= bcdiv($temp,
$key->cr_tantieme);
87 if ( $afd->afd_amount != 0 )$afd->insert();
92 catch (Exception $exc)
94 echo $exc->getTraceAsString();
105 $this->type =
"amount";
106 $this->af_amount = $p_array[
'amount'];
107 $this->cr_id = $p_array[
'key'];
108 $this->af_percent = 1;
111 if (isDate($p_array[
'p_date']) == null)
112 throw new Exception(
'La date est invalide');
113 $this->af_ledger = $p_array[
'p_jrn'];
114 $this->af_date = $p_array[
'p_date'];
116 $fiche->get_by_qcode($p_array[
'w_categorie_appel']);
119 throw new Exception(
"La fiche pour l'appel de fond n'existe pas");
120 $this->af_card =
$fiche->id;
136 if ($p_array[
'bud_pct'] > 100 || $p_array[
'bud_pct']<0 )
throw new Exception (
'Pourcentage incorrect');
138 if ( isDate($p_array[
'p_date'])==null)
throw new Exception(
'La date est invalide');
140 $this->type=
"budget";
141 $this->
b_id=$p_array[
'b_id'];
142 $this->af_percent=$p_array[
'bud_pct']/100;
143 $this->af_ledger=$p_array[
'p_jrn'];
144 $this->af_date=$p_array[
'p_date'];
146 $fiche->get_by_qcode($p_array[
'w_categorie_appel']);
148 if (
$fiche->id < 1 )
throw new Exception(
"La fiche pour l'appel de fond n'existe pas");
149 $this->af_card=
$fiche->id;
152 $tot_bud=$cn->get_value(
'select b_amount from coprop.budget where b_id=$1',array($this->
b_id));
153 if ($tot_bud <=0 )
throw new Exception (
"Ce budget a un montant de 0 ");
155 $this->af_amount= bcmul($tot_bud,$this->af_percent);
160 $budget->b_id=$this->b_id;
162 $a_detail=$budget->get_detail();
166 for ($i=0;$i<count($a_detail);$i++)
169 $amount= bcmul($a_detail[$i][
'bt_amount'],$this->af_percent);
170 $key=$a_detail[$i][
'cr_id'];
176 }
catch (Exception $e)
185 $ledger =
new Acc_Ledger($cn,$this->af_ledger);
186 $adetail = $cn->get_array(
"
187 select sum(afd_amount) as amount,S.coprop_id
188 from coprop.appel_fond_detail as A
189 join coprop.summary as S on (S.lot_id::numeric=A.lot_id)
190 where af_id=$1 group by S.coprop_id", array($this->
id));
193 $array[
'e_date'] = $this->af_date;
194 $array[
'p_jrn'] = $this->af_ledger;
195 $array[
'desc']=
"Appel de fond";
196 $fiche=
new Fiche($cn,$this->af_card);
198 $array[
'amount0']=$this->af_amount;
201 $array[
'nb_item']=$max_line;
203 for ($i=0;$i<count($adetail);$i++){
205 $fiche=
new Fiche($cn,$adetail[$i][
'coprop_id']);
207 $array[
'amount'.$idx]=round($adetail[$i][
'amount'],2);
211 echo
'<FORM METHOD="GET" class="print">';
213 echo HtmlInput::request_to_hidden(array(
'amount',
'key',
'w_categorie_appel',
'b_id',
'aft',
'bud_pct',
'p_date',
'ac',
'plugin_code',
'sa'));
214 echo HtmlInput::extension() . dossier::hidden();
215 echo HtmlInput::hidden(
'action',
'confirm');
216 echo HtmlInput::hidden(
'af_id', $this->
id);
217 echo HtmlInput::submit(
'save',
'Sauve');
218 echo HtmlInput::button(
'add', _(
'Ajout d\'une ligne'),
'onClick="quick_writing_add_row()"');
220 echo
'<div class="info">' .
221 _(
'Débit') .
' = <span id="totalDeb"></span> ' .
222 _(
'Crédit') .
' = <span id="totalCred"></span> ' .
223 _(
'Difference') .
' = <span id="totalDiff"></span></div> ';
224 echo
"<script>checkTotalDirect();</script>";
230 $cn->exec_sql(
"update coprop.appel_fond set af_confirmed='Y',jr_internal=$2 where af_id=$1",array($this->
id,$this->
jr_internal));
manage the table coprop.appel_fond_detail
if(isset($_POST['remove'])) $array
compute_key($p_key_id, $p_amount)
create_key()
create a key to save the data in DB
if($p_number->value==0) l les annuités seront recalculées et l pct[] ad_year[] select jr_internal