phpcompta-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpcompta-dev] r289 - in trunk/coprop: . include


From: phpcompta-dev
Subject: [Phpcompta-dev] r289 - in trunk/coprop: . include
Date: Fri, 13 Jan 2012 23:19:47 +0100 (CET)

Author: danydb
Date: 2012-01-13 23:19:46 +0100 (Fri, 13 Jan 2012)
New Revision: 289

Removed:
   trunk/coprop/include/class_budget.php
Modified:
   trunk/coprop/coprop-constant.php
   trunk/coprop/include/ajax_bud_display.php
   trunk/coprop/include/appel_fond.inc.php
   trunk/coprop/include/budget.inc.php
   trunk/coprop/include/class_copro_key.php
   trunk/coprop/include/class_coprop_appel_fond.php
Log:

appel de fond : calcul et sauvegarde


Modified: trunk/coprop/coprop-constant.php
===================================================================
--- trunk/coprop/coprop-constant.php    2012-01-13 14:29:05 UTC (rev 288)
+++ trunk/coprop/coprop-constant.php    2012-01-13 22:19:46 UTC (rev 289)
@@ -9,6 +9,8 @@
 
 require_once ('class_database.php');
 require_once 'include/class_copro_parameter.php';
+require_once 'class_acc_ledger.php';
+
 global $cn,$g_copro_parameter,$gDossier;
 $cn=Dossier::connect();
 $gDossier=Dossier::id();

Modified: trunk/coprop/include/ajax_bud_display.php
===================================================================
--- trunk/coprop/include/ajax_bud_display.php   2012-01-13 14:29:05 UTC (rev 
288)
+++ trunk/coprop/include/ajax_bud_display.php   2012-01-13 22:19:46 UTC (rev 
289)
@@ -2,9 +2,9 @@
 /**
  * @file montre détail budget pour mise à jour
  */
-require_once 'class_budget.php';
+require_once 'class_copro_budget.php';
 
-$bud=new Budget();
+$bud=new Copro_Budget();
 $bud->b_id=$bud_id;
 echo '<form id="fbud_update" method="post">';
 $bud->detail();

Modified: trunk/coprop/include/appel_fond.inc.php
===================================================================
--- trunk/coprop/include/appel_fond.inc.php     2012-01-13 14:29:05 UTC (rev 
288)
+++ trunk/coprop/include/appel_fond.inc.php     2012-01-13 22:19:46 UTC (rev 
289)
@@ -45,17 +45,17 @@
                 break;
             case 1:
                 $appel_fond = new Coprop_Appel_Fond();
-                $error = $appel_fond->compute_budget($_GET);
+                $appel_fond->compute_budget($_GET);
                 break;
             case 2:
                 $appel_fond = new Coprop_Appel_Fond();
-                $error = $appel_fond->compute_amount($_GET);
+                 $appel_fond->compute_amount($_GET);
                 break;
         }
-        
+
         $appel_fond->display_ledger();
-        
-        
+
+
         exit();
     }
     catch (Exception $e)
@@ -63,26 +63,56 @@
         alert($e->getMessage());
     }
 }
+// save
+if ( isset($_POST['confirm']))
+{
+       $ledger=new Acc_Ledger($cn,$_POST['p_jrn']);
+       $ledger->with_concerned=false;
+       $ledger->save($_POST);
+       echo "<h2>Opération sauvée</h2>";
+       echo HtmlInput::detail_op($ledger->jr_id,$ledger->internal);
+       echo $ledger->input($_GET,1);
+       $appel_fond = new Coprop_Appel_Fond();
+       $appel_fond->id=$_POST['af_id'];
+       $appel_fond->confirm();
+       exit();
+}
 // Montre écran confirmation
+if ( isset ($_GET['save']))
+{
+       /**
+        address@hidden manque correction
+        */
+       echo '<form method="POST">';
+       $ledger=new Acc_Ledger($cn,$_GET['p_jrn']);
+       $ledger->with_concerned=false;
+       echo $ledger->input($_GET,1);
+       echo HtmlInput::submit('confirm','Confirmer');
+       echo '</form>';
+       exit();
+}
 
 
-// confirmation
 
-
 // Detail : propose de faire un appel de fond
 $date = new IDate('p_date');
+$date->value=HtmlInput::default_value('p_date',"",$_GET);
+
 $amount = new INum('amount');
+$amount->value=HtmlInput::default_value('amount',0,$_GET);
 
 $ledger = new Acc_Ledger($cn, 0);
 $led_appel_fond = $ledger->select_ledger('ODS', 3);
-$led_appel_fond->selected = $g_copro_parameter->journal_appel;
+$led_appel_fond->selected = 
(isset($_GET['p_jrn']))?$_GET['p_jrn']:$g_copro_parameter->journal_appel;
+
 $copro = new ICard();
 $categorie_appel = new ICard();
 $categorie_appel->label = " Appel de fond : " . HtmlInput::infobulle(0);
 $categorie_appel->name = "w_categorie_appel";
 $categorie_appel->tabindex = 1;
-$categorie_appel->value = "";
+$categorie_appel->value = 
isset($_GET['w_categorie_appel'])?$_GET['w_categorie_appel']:"";
 $categorie_appel->table = 0;
+$categorie_appel->selected=(isset($_GET['key']))?$_GET['key']:-1;
 
 // name of the field to update with the name of the card
 $categorie_appel->set_attribute('label', 'w_categorie_appel_label');
@@ -110,6 +140,7 @@
 
 $key = new ISelect("key");
 $key->value = $cn->make_array("select cr_id,cr_name from 
coprop.clef_repartition");
+$key->selected=HtmlInput::default_value('key',-1,$_GET);
 
 $f_add_button = new IButton('add_card');
 $f_add_button->label = _('Nouvelle fiche ');
@@ -122,23 +153,25 @@
 // Budget
 $budget_sel = new ISelect("b_id");
 $budget_sel->value = $cn->make_array("select b_id,b_name from coprop.budget 
order by b_name");
+$budget_sel->selected=HtmlInput::default_value('b_id',-1,$_GET);
 
 // pourcentage
 $budget_pct = new INum("bud_pct", 0);
+$budget_pct->value=HtmlInput::default_value('bud_pct',0,$_GET);
 
 // select between budget or amount
 $appel_fond_type = new ISelect("aft");
 $appel_fond_type->value = array(
     array("value" => -1, 'label' => 'Faites votre choix'),
-    array("value" => 1, 'label' => 'Appel de fond d\'budget'),
+    array("value" => 1, 'label' => 'Appel de fond par budget'),
     array("value" => 2, 'label' => 'Appel de fond par montant')
 );
 $onchange = " onchange=\"appel_fond_show() \"";
 $appel_fond_type->javascript = $onchange;
+$appel_fond_type->selected=HtmlInput::default_value('aft',-1,$_GET);
 
-
 echo '<form method="get">';
-echo HtmlInput::request_to_hidden(array('ac', 'plugin_code', 'sa'));
+echo HtmlInput::request_to_hidden(array('ac', 'plugin_code', 'sa','gDossier'));
 require_once 'template/appel_fond.php';
 echo HtmlInput::submit('calc', "Calculer");
 echo '</form>';

Modified: trunk/coprop/include/budget.inc.php
===================================================================
--- trunk/coprop/include/budget.inc.php 2012-01-13 14:29:05 UTC (rev 288)
+++ trunk/coprop/include/budget.inc.php 2012-01-13 22:19:46 UTC (rev 289)
@@ -4,8 +4,8 @@
  * @file gestion des budgets
  */
 
-require_once 'class_budget.php';
-$bud=new Budget();
+require_once 'class_copro_budget.php';
+$bud=new Copro_Budget();
 
 if ( isset ($_POST['bud_update']))
 {

Deleted: trunk/coprop/include/class_budget.php
===================================================================
--- trunk/coprop/include/class_budget.php       2012-01-13 14:29:05 UTC (rev 
288)
+++ trunk/coprop/include/class_budget.php       2012-01-13 22:19:46 UTC (rev 
289)
@@ -1,322 +0,0 @@
-<?php
-
-
-class Budget
-{
-    function to_list()
-    {
-        global $cn;
-
-        $array=$cn->get_array("select b_id, b_name,
-                    to_char(b_start,'DD.MM.YYYY') as str_start,
-                    to_char(b_end,'DD.MM.YYYY') as str_end,
-                    b_amount
-                    from coprop.budget
-                    order by b_name
-                    ");
-
-        require_once 'template/budget_list.php';
-
-    }
-       function load()
-       {
-               global $cn;
-               try
-               {
-                       if ($this->b_id == '') throw new Exception("Aucun 
budget demandé");
-                       $array=$cn->get_array("select 
b_id,b_name,b_start,b_end,b_amount,
-                               to_char(b_start,'DD.MM.YYYY') as str_b_start,
-                               to_char(b_end,'DD.MM.YYYY') as str_b_end
-                               from coprop.budget where 
b_id=$1",array($this->b_id));
-                       if ($cn->count() == 1)
-                       {
-                               $this->b_name=$array[0]['b_name'];
-                               $this->b_start=$array[0]['b_start'];
-                               $this->str_b_start=$array[0]['str_b_start'];
-                               $this->b_end=$array[0]['b_end'];
-                               $this->str_b_end=$array[0]['str_b_end'];
-                               $this->b_amount=$array[0]['b_amount'];
-                       }
-                       else
-                               throw new Exception ('Aucun budget trouvé');
-               } catch (Exception $e)
-               {
-                       echo $e->getTraceAsString();
-                       throw $e;
-               }
-       }
-       /**
-        *Detail d'un budget avec les détails, pour mettre à jour
-        * @global type $cn
-        * @throws Exception
-        */
-    function detail()
-    {
-        global $cn;
-        try
-        {
-
-            if ( ! isset ($this->b_id)|| trim($this->b_id)=='')
-                    throw new Exception ("Aucun budget demandé");
-                       $name=new IText('b_name');
-                       if ($this->b_id <> 0)
-                       {
-                               $this->load();
-                               $name->value=$this->b_name;
-                               $start=new IDate('b_start',$this->str_b_start);
-                               $end=new IDate('b_end',$this->str_b_end);
-                               $amount=new 
INum('b_amount',round($this->b_amount,2));
-
-                       }       else {
-                               $start=new IDate('b_start');
-                               $end=new IDate('b_end');
-                               $amount=new INum('b_amount',0);
-
-                       }
-                       
$amount->javascript='onchange="format_number(this,2);compute_budget();"';
-                       $bud_amount=$amount->value;
-
-                       echo HtmlInput::hidden("b_id",$this->b_id);
-                       echo 
HtmlInput::request_to_hidden(array('gDossier','ac','plugin_code','sa'));
-                       require_once 'template/budget.php';
-
-            $array=$cn->get_array("select bt_label,
-                                                       
bt_id,bt_amount,f_id,vw_name,quick_code,cr_name,cr_id
-                from coprop.budget_detail
-                join coprop.clef_repartition using (cr_id)
-                join vw_fiche_attr using (f_id)
-                where b_id=$1",array($this->b_id));
-            $a_input=array();
-            $fiche_dep=$cn->make_list("select fd_id from fiche_def where 
frd_id=2");
-
-                       $a_key=$cn->make_array(" select cr_id,cr_name from 
coprop.clef_repartition order by cr_name");
-                       $max=count($array);
-            for ($i=0;$i<MAXROWBUD;$i++)
-            {
-                               $label=new IText('bt_label[]');
-                               
$label->value=($i>=$max)?"":$array[$i]['bt_label'];
-
-                $card=new ICard('f_id'.$i);
-                $card->value=($i>=$max)?"":$array[$i]['quick_code'];
-                $card->table=0;
-
-                 // name of the field to update with the name of the card
-                $card->set_attribute('label','w_card_label'.$i);
-
-                // Type of card : deb, cred,
-                $card->set_attribute('typecard',$fiche_dep);
-
-                $card->extra=$fiche_dep;
-
-                // Add the callback function to filter the card on the jrn
-                $card->set_callback('filter_card');
-                $card->set_attribute('ipopup','ipopcard');
-                // when value selected in the autcomplete
-                  $card->set_function('fill_data');
-
-                // when the data change
-
-                  $card->javascript=sprintf(' 
onchange="fill_data_onchange(\'%s\');" ',
-                            $card->name);
-                  $card->set_dblclick("fill_ipopcard(this);");
-
-                  $card_label=new ISpan();
-                  $card_label->table=0;
-                  $f_card_label=$card_label->input("w_card_label".$i,"");
-
-                // Search button for card
-                $f_card_bt=$card->search();
-
-                $amount=new INum("bt_amount[]");
-                $amount->value=($i>=$max)?"":round($array[$i]['bt_amount'],2);
-                               
$amount->javascript='onchange="format_number(this,2);compute_budget();"';
-                
$hidden=($i>=$max)?HtmlInput::hidden("bt_id[]",0):HtmlInput::hidden("bt_id[]",$array[$i]["bt_id"]);
-                               echo $hidden;
-
-                $ikey=new ISelect("key[]");
-                $ikey->value=$a_key;
-                $ikey->selected=($i>=$max)?0:$array[$i]['cr_id'];
-
-                $a_input[$i]["amount"]=$amount->input();
-                $a_input[$i]["hidden"]=$hidden;
-                $a_input[$i]["card"]=$card->input().$f_card_bt;
-                $a_input[$i]["card_label"]=$label->input();
-
-                $a_input[$i]['key']=$ikey->input();
-
-            }
-            require_once 'template/bud_detail.php';
-                       echo create_script("compute_budget()");
-        }
-        catch (Exception $e)
-        {
-            $e->getTraceAsString();
-                       throw $e;
-        }
-    }
-       /**
-        address@hidden insert or update a new budget
-        * @param $p_array
-        *   - b_id
-        *   - b_name
-        *   - b_start
-        *   - b_end
-        *   - b_amount
-        *   - f_idX  -> qcode
-        *   - key[X]
-        *   - bt_amount[X]
-        *   - p_jrn
-        *   - bt_id[X]
-        */
-       function save($p_array)
-       {
-               try{
-                       $this->b_id=$p_array['b_id'];
-                       if ( $p_array['b_id'] == 0 )
-                       {
-                               $this->insert($p_array);
-                               $this->save_detail($p_array);
-                       } else {
-                               $this->update($p_array);
-                               $this->save_detail($p_array);
-                       }
-               }
-               catch( Exception $e){
-                       throw $e;
-               }
-       }
-       /**
-        address@hidden update budget
-        */
-       function update($p_array)
-       {
-               global $cn;
-               try {
-                       extract ($p_array);
-                       // update coprop.budget
-                       $cn->exec_sql("update coprop.budget set b_name=$1,
-                                       b_start=to_date($2,'DD.MM.YYYY'),
-                                       b_end=to_date($3,'DD.MM.YYYY'),
-                                       b_amount=$4
-                                       where b_id=$5
-                                       ",array(
-                                               strip_tags($b_name),
-                                               $b_start,
-                                               $b_end,
-                                               $b_amount,
-                                               $b_id
-                                       ));
-
-
-               }
-               catch (Exception $exc) {
-                       echo $exc->getTraceAsString();
-                       throw $exc;
-               }
-
-       }
-       /**
-        address@hidden insert budget
-        */
-       function insert($p_array)
-       {
-               global $cn;
-               try {
-                       extract ($p_array);
-                       // update coprop.budget
-                       $this->b_id=$cn->get_value("insert into coprop.budget 
(b_name,b_start,b_end,b_amount)
-                               values ($1,
-                                       to_date($2,'DD.MM.YYYY'),
-                                       to_date($3,'DD.MM.YYYY'),
-                                       $4) returning b_id
-                                       ",array(
-                                               strip_tags($b_name),
-                                               $b_start,
-                                               $b_end,
-                                               $b_amount
-                                       ));
-
-
-               }
-               catch (Exception $exc) {
-                       echo $exc->getTraceAsString();
-                       throw $exc;
-               }
-
-       }
-       function save_detail($p_array)
-       {
-               extract($p_array);
-               global $cn;
-               try
-               {
-                       $max=count($bt_id);
-                       for ($i=0;$i<MAXROWBUD;$i++)
-                       {
-
-                               if ( $bt_id[$i]== 0)
-                               {
-                                       if ( strlen(trim(${'f_id'.$i})) != 0)
-                                       {
-                                               $f_id=$cn->get_value("select 
f_id from vw_fiche_attr where quick_code=upper(trim($1))",
-                                                               
array(${'f_id'.$i}));
-
-                                               // insert into 
coprop.budget_detail
-                                                       $cn->exec_sql("insert 
into coprop.budget_detail (bt_label,f_id,b_id,bt_amount,cr_id) ".
-                                                               " values 
($1,$2,$3,$4,$5)",
-                                                               array(
-                                                                       
strip_tags($bt_label[$i]),
-                                                                       $f_id,
-                                                                       
$this->b_id,
-                                                                       
$bt_amount[$i],
-                                                                       $key[$i]
-                                                                       )
-
-                                                       );
-                                       }
-                               }
-                               else
-                               {
-                                       // update into coprop.budget_detail
-                                       if ( strlen(trim(${'f_id'.$i})) != 0)
-                                       {
-                                               $f_id=$cn->get_value("select 
f_id from vw_fiche_attr where quick_code=upper(trim($1))",
-                                                               
array(${'f_id'.$i}));
-
-                                               $cn->exec_sql("update 
coprop.budget_detail set bt_label=$1,f_id=$2,bt_amount=$3,cr_id=$4 ".
-                                                               " where 
bt_id=$5",
-                                                               array(
-                                                                       
strip_tags($bt_label[$i]),
-                                                                       $f_id,
-                                                                       
$bt_amount[$i],
-                                                                       
$key[$i],
-                                                                       
$bt_id[$i]
-                                                                       )
-
-                                                       );
-
-                                       } else {
-                                               $cn->exec_sql("delete from 
coprop.budget_detail where bt_id=$1",array($bt_id[$i]));
-                                       }
-
-                               }
-                       }
-
-
-               }
-               catch (Exception $exc)
-               {
-                       echo $exc->getTraceAsString();
-                       throw $exc;
-               }
-
-       }
-       function get_detail()
-       {
-           global $cn;
-           $array=$cn->get_array("select * from coprop.budget_detail where 
b_id=$1",
-                   array($this->b_id));
-           return $array;
-       }
-}
-?>

Modified: trunk/coprop/include/class_copro_key.php
===================================================================
--- trunk/coprop/include/class_copro_key.php    2012-01-13 14:29:05 UTC (rev 
288)
+++ trunk/coprop/include/class_copro_key.php    2012-01-13 22:19:46 UTC (rev 
289)
@@ -20,7 +20,7 @@
 /* $Revision$ */
 
 // Copyright Author Dany De Bontridder address@hidden
-
+require_once 'class_copro_appel_fond_detail.php';
 /**
  * @file
  * @brief Gère les clefs
@@ -99,7 +99,7 @@
         {
             global $cn;
             $array=$cn->get_array("select * from coprop.clef_repartition where
-                cr_id=$1",$this->cr_id);
+                cr_id=$1",array($this->cr_id));
             if ( $cn->count() == 1 )
             {
                 foreach ( array("cr_id","cr_name","cr_note","cr_tantieme") as 
$k=>$e) {

Modified: trunk/coprop/include/class_coprop_appel_fond.php
===================================================================
--- trunk/coprop/include/class_coprop_appel_fond.php    2012-01-13 14:29:05 UTC 
(rev 288)
+++ trunk/coprop/include/class_coprop_appel_fond.php    2012-01-13 22:19:46 UTC 
(rev 289)
@@ -1,26 +1,43 @@
 <?php
 /**
- address@hidden calcul appel de fond 
+ address@hidden calcul appel de fond
  */
 require_once 'class_copro_key.php';
 require_once 'class_copro_budget.php';
 class Coprop_Appel_Fond
 {
+       function load()
+       {
+               global $cn;
+               $array=$cn->get_array("SELECT af_id, 
to_char(af_date,'DD.MM.YYYY') as af_date,
+                                       af_confirmed, af_percent, af_amount, 
af_card,
+                                       af_ledger, tech_per, jr_internal, b_id, 
cr_id
+                                               FROM coprop.appel_fond where 
af_id=$1",
+                               array($this->id));
+
+               
$var=array('af_id','af_date','af_confirmed','af_percent','af_amount','af_card','af_ledger','tech_per','jr_internal','b_id','cr_id');
+               for ($i=0;$i<count($array);$i++)
+               {
+                       $idx=$var[$i];
+                       $this->$idx=$array[0][$idx];
+               }
+
+       }
     /**
-     address@hidden create a key to save the data in DB 
+     address@hidden create a key to save the data in DB
      */
     function create_key()
     {
         global $cn;
-        $this->id=$cn->get_next_seq('appel_fond_id');
+        $this->id=$cn->get_next_seq('coprop.appel_fond_id');
         // clean old
-        $this->exec_sql("delete from coprop.appel_fond where af_confirmed='N' 
and tech_per < tech_per - interval '5 hours' )");
-        
+        $cn->exec_sql("delete from coprop.appel_fond where af_confirmed='N' 
and tech_per < tech_per - interval '5 hours' ");
+
         // insert new unconfirmed
         $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)
-                values 
($1,to_date($2,'DD.MM.YYYY','N',$3,$4,$5,$6,$7,now()),$8",
-                
array($this->id,$this->af_date,$this->percent,$this->amount,$this->af_card,$this->af_ledger,$this->b_id,$this->cr_id));
-        
+                values 
($1,to_date($2,'DD.MM.YYYY'),'N',$3,$4,$5,$6,now(),$7,$8)",
+                
array($this->id,$this->af_date,$this->af_percent,$this->af_amount,$this->af_card,$this->af_ledger,$this->b_id,$this->cr_id));
+
     }
     function compute_key($p_key_id,$p_amount)
     {
@@ -32,7 +49,7 @@
             $key=new Copro_Key();
             $key->cr_id=$p_key_id;
             $key->load();
-            
+
             bcscale(4);
             $a_lot=$key->get_detail();
             for ($i=0;$i<count($a_lot);$i++)
@@ -43,14 +60,15 @@
                 $afd->key_id=$p_key_id;
                 $afd->key_tantieme=$key->cr_tantieme;
                 $afd->lot_tantieme=$a_lot[$i]['crd_amount'];
-                
-                $fract=bcsub($key->cr_tantieme,$a_lot[$i]['crd_amount']);
-                $afd->afd_amount=$fract;
-                
+
+                $fract=  bcdiv($a_lot[$i]['crd_amount'],$key->cr_tantieme);
+
+                $afd->afd_amount=  bcmul($fract,$p_amount);
+
                 $afd->insert();
-                
+
             }
-            
+                       $cn->commit();
         }
         catch (Exception $exc)
         {
@@ -62,13 +80,13 @@
     function compute_amount($p_array)
     {
         global $cn;
-        bcscale(2);
+        bcscale(4);
         try
         {
             $this->type = "amount";
             $this->af_amount = $p_array['amount'];
-            $this->cr_id = $p_array['cr_id'];
-            $this->percent = 1;
+            $this->cr_id = $p_array['key'];
+            $this->af_percent = 1;
             $this->b_id = null;
             // req date valide
             if (isDate($p_array['p_date']) == null)
@@ -92,17 +110,17 @@
     function compute_budget($p_array)
     {
         global $cn;
-        bcscale(2);
-        try 
+        bcscale(4);
+        try
         {
             // req bud_pct <= 1 && bud_pct > 0
             if ($p_array['bud_pct'] > 1 || $p_array['bud_pct']<0 ) throw new 
Exception ('Pourcentage incorrect');
             // req date valide
             if ( isDate($p_array['p_date'])==null) throw new Exception('La 
date est invalide');
-            
+
             $this->type="budget";
             $this->b_id=$p_array['b_id'];
-            $this->percent=$p_array['bud_pct'];
+            $this->af_percent=$p_array['bud_pct'];
             $this->af_ledger=$p_array['p_jrn'];
             $this->af_date=$p_array['p_date'];
             $fiche=new Fiche($cn);
@@ -110,30 +128,31 @@
             //  req  $fiche->id > 0
             if ( $fiche->id < 1 ) throw new Exception("La fiche pour l'appel 
de fond n'existe pas");
             $this->af_card=$fiche->id;
+                       $this->cr_id=null;
 
             $tot_bud=$cn->get_value('select b_amount from coprop.budget where 
b_id=$1',array($this->b_id));
             if ($tot_bud <=0  ) throw new Exception ("Ce budget a un montant 
de 0 ");
 
-            $this->af_amount=  bcmul($tot_bud,$this->percent);
+            $this->af_amount=  bcmul($tot_bud,$this->af_percent);
             $this->create_key();
-            
+
             // get all the key of this budget
-            $budget=new Budget();
+            $budget=new Copro_Budget();
             $budget->b_id=$this->b_id;
-            
+
             $a_detail=$budget->get_detail();
             bcscale(4);
-            
-            // foreach key, 
+
+            // foreach key,
             for ($i=0;$i<count($a_detail);$i++)
             {
-                //  compute the amount to take 
-                $amount=$a_detail[$i]['bt_amount'];
+                //  compute the amount to take
+                $amount=  bcmul($a_detail[$i]['bt_amount'],$this->af_percent);
                 $key=$a_detail[$i]['cr_id'];
 
                 // call compute_key
                 $this->compute_key($key, $amount);
-                
+
             }
         } catch (Exception $e)
         {
@@ -141,8 +160,53 @@
         }
     }
     function display_ledger()
-    {
-        
-    }
+       {
+               global $cn;
+               $ledger = new Acc_Ledger($cn,0);
+               $this->load();
+               $adetail = $cn->get_array("
+                       select sum(afd_amount) as amount,S.coprop_id
+                               from coprop.appel_fond_detail as A
+                               join coprop.summary as S on 
(S.lot_id::numeric=A.lot_id)
+                       where af_id=$1 group by S.coprop_id", array($this->id));
+               $array[] = array();
+
+               $array['e_date'] = $this->af_date;
+               $array['p_jrn'] = $this->af_ledger;
+               $array['desc']="Appel de fond";
+               $fiche=new Fiche($cn,$this->af_card);
+               $array['qc_0']=$fiche->get_quick_code();
+               $array['amount0']=$this->af_amount;
+               $array['nb']=count($adetail);
+
+               for ($i=0;$i<count($adetail);$i++){
+                       $idx=$i+1;
+                       $fiche=new Fiche($cn,$adetail[$i]['coprop_id']);
+                       $array['qc_'.$idx]=$fiche->get_quick_code();
+                       $array['amount'.$idx]=round($adetail[$i]['amount'],2);
+                       $array['ck'.$idx]=1;
+               }
+
+               echo '<FORM METHOD="GET" class="print">';
+               echo $ledger->input($array,0);
+               echo HtmlInput::request_to_hidden(array('ac', 
'plugin_code','sa'));
+               echo HtmlInput::extension() . dossier::hidden();
+               echo HtmlInput::hidden('action', 'confirm');
+               echo HtmlInput::hidden('af_id', $this->id);
+               echo HtmlInput::submit('save', 'Sauve');
+               echo HtmlInput::button('add', _('Ajout d\'une ligne'), 
'onClick="quick_writing_add_row()"');
+               echo '</form>';
+               echo '<div class="info">' .
+               _('Débit') . ' = <span id="totalDeb"></span>  ' .
+               _('Crédit') . ' = <span id="totalCred"></span>  ' .
+               _('Difference') . ' = <span id="totalDiff"></span></div> ';
+               echo "<script>checkTotalDirect();</script>";
+               echo '</div>';
+       }
+       function confirm()
+       {
+               global $cn;
+               $cn->exec_sql("update coprop.appel_fond set af_confirmed='Y' 
where af_id=$1",array($this->id));
+       }
 }
 ?>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]