phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r286 - trunk/coprop/include


From: phpcompta-dev
Subject: [Phpcompta-dev] r286 - trunk/coprop/include
Date: Thu, 12 Jan 2012 17:12:18 +0100 (CET)

Author: danydb
Date: 2012-01-12 17:12:17 +0100 (Thu, 12 Jan 2012)
New Revision: 286

Added:
   trunk/coprop/include/class_coprop_appel_fond.php
Modified:
   trunk/coprop/include/appel_fond.inc.php
   trunk/coprop/include/class_install_plugin.php
Log:
appel de fond  : create key 

Modified: trunk/coprop/include/appel_fond.inc.php
===================================================================
--- trunk/coprop/include/appel_fond.inc.php     2012-01-12 13:44:16 UTC (rev 
285)
+++ trunk/coprop/include/appel_fond.inc.php     2012-01-12 16:12:17 UTC (rev 
286)
@@ -27,81 +27,108 @@
  *
  */
 global $cn, $g_copro_parameter;
+require_once 'class_coprop_appel_fond.php';
+extract($_GET);
+$error = 0;
 
-extract($_GET);
-if (isset($genere))
+// Demande génération
+if (isset($calc))
 {
-    // Génére écriture comptable dans journal choisi
+// Génére écriture comptable dans journal choisi
+    switch ($aft)
+    {
+        case -1:
+        $error = 1;
+        alert("Choississez le type de calcul");
+        break;
+        case 1:
+            $appel_fond=new Coprop_Appel_Fond();
+            $error=$appel_fond->compute_budget($_GET);
+            break;
+        case 2:
+            $appel_fond=new Coprop_Appel_Fond();
+            $error=$appel_fond->compute_amount($_GET);
+            break;
+    }
+    if ($error == 0)        exit();
 }
-else
-{
-    $date = new IDate('p_date');
-    $amount = new INum('amount');
+// Montre écran confirmation
 
-    $ledger = new Acc_Ledger($cn, 0);
-    $led_appel_fond = $ledger->select_ledger('ODS', 3);
-    $led_appel_fond->selected = $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->table = 0;
 
-    // name of the field to update with the name of the card
-    $categorie_appel->set_attribute('label', 'w_categorie_appel_label');
-    // Type of card : deb, cred,
-    $categorie_appel->set_attribute('typecard', 
$g_copro_parameter->categorie_appel);
+// confirmation
 
-    $categorie_appel->extra = $g_copro_parameter->categorie_appel;
 
+// Detail : propose de faire un appel de fond
+$date = new IDate('p_date');
+$amount = new INum('amount');
+
+$ledger = new Acc_Ledger($cn, 0);
+$led_appel_fond = $ledger->select_ledger('ODS', 3);
+$led_appel_fond->selected = $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->table = 0;
+
+// name of the field to update with the name of the card
+$categorie_appel->set_attribute('label', 'w_categorie_appel_label');
+// Type of card : deb, cred,
+$categorie_appel->set_attribute('typecard', 
$g_copro_parameter->categorie_appel);
+
+$categorie_appel->extra = $g_copro_parameter->categorie_appel;
+
 // Add the callback function to filter the card on the jrn
-    $categorie_appel->set_callback('filter_card');
-    $categorie_appel->set_attribute('ipopup', 'ipopcard');
+$categorie_appel->set_callback('filter_card');
+$categorie_appel->set_attribute('ipopup', 'ipopcard');
 // when value selected in the autcomplete
-    $categorie_appel->set_function('fill_data');
+$categorie_appel->set_function('fill_data');
 
 // when the data change
-    $categorie_appel->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $categorie_appel->name);
-    $categorie_appel->set_dblclick("fill_ipopcard(this);");
+$categorie_appel->javascript = sprintf(' 
onchange="fill_data_onchange(\'%s\');" ', $categorie_appel->name);
+$categorie_appel->set_dblclick("fill_ipopcard(this);");
 
-    $categorie_appel_label = new ISpan();
-    $categorie_appel_label->table = 0;
-    $f_categorie_appel_label = 
$categorie_appel_label->input("w_categorie_appel_label", "");
+$categorie_appel_label = new ISpan();
+$categorie_appel_label->table = 0;
+$f_categorie_appel_label = 
$categorie_appel_label->input("w_categorie_appel_label", "");
 
 // Search button for card
-    $f_categorie_appel_bt = $categorie_appel->search();
+$f_categorie_appel_bt = $categorie_appel->search();
 
-    $key = new ISelect("key");
-    $key->value = $cn->make_array("select cr_id,cr_name from 
coprop.clef_repartition");
+$key = new ISelect("key");
+$key->value = $cn->make_array("select cr_id,cr_name from 
coprop.clef_repartition");
 
-    $f_add_button = new IButton('add_card');
-    $f_add_button->label = _('Nouvelle fiche ');
-    $f_add_button->set_attribute('ipopup', 'ipop_newcard');
-    $f_add_button->set_attribute('jrn', -1);
-    $filter = $g_copro_parameter->categorie_appel;
-    $f_add_button->javascript = " 
this.filter='$filter';this.jrn=-1;select_card_type(this);";
-    $str_add_appel = $f_add_button->input();
-    
- // 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");
-    
-    // pourcentage
-    $budget_pct=new INum("bud_pct",0);
-    
-    // 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"=>2,'label'=>'Appel de fond par montant')
-    );
-    $onchange=" onchange=\"appel_fond_show() \"";
-    $appel_fond_type->javascript=$onchange;
-    
-    
-    require_once 'template/appel_fond.php';
-}
+$f_add_button = new IButton('add_card');
+$f_add_button->label = _('Nouvelle fiche ');
+$f_add_button->set_attribute('ipopup', 'ipop_newcard');
+$f_add_button->set_attribute('jrn', -1);
+$filter = $g_copro_parameter->categorie_appel;
+$f_add_button->javascript = " 
this.filter='$filter';this.jrn=-1;select_card_type(this);";
+$str_add_appel = $f_add_button->input();
+
+// 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");
+
+// pourcentage
+$budget_pct = new INum("bud_pct", 0);
+
+// 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" => 2, 'label' => 'Appel de fond par montant')
+);
+$onchange = " onchange=\"appel_fond_show() \"";
+$appel_fond_type->javascript = $onchange;
+
+
+echo '<form method="get">';
+echo HtmlInput::request_to_hidden('ac', 'plugin_code', 'sa');
+require_once 'template/appel_fond.php';
+echo HtmlInput::submit('calc', "Calculer");
+echo '</form>';
 ?>

Added: trunk/coprop/include/class_coprop_appel_fond.php
===================================================================
--- trunk/coprop/include/class_coprop_appel_fond.php                            
(rev 0)
+++ trunk/coprop/include/class_coprop_appel_fond.php    2012-01-12 16:12:17 UTC 
(rev 286)
@@ -0,0 +1,65 @@
+<?php
+/**
+ address@hidden calcul appel de fond 
+ */
+
+class Coprop_Appel_Fond
+{
+    /**
+     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');
+        // clean old
+        $this->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)
+                values 
($1,to_date($2,'DD.MM.YYYY','N',$3,$4,$5,$6,$7,now())",array($this->id,$this->af_date,$this->percent,$this->amount,$this->bud_id,$this->af_card,$this->af_ledger));
+        
+    }
+    function compute_amount($p_array)
+    {
+        $this->type="amount";
+        $this->amount=0;
+        $this->percent=1;
+        $this->bud_id=null;
+        
+        $this->create_key();
+    }
+    function compute_budget($p_array)
+    {
+        global $cn;
+        bcscale(2);
+        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->bud_id=$p_array['b_id'];
+            $this->percent=$p_array['bud_pct'];
+            $this->af_ledger=$p_array['p_jrn'];
+            $this->af_date=$p_array['p_date'];
+            $fiche=new Fiche($cn);
+            $fiche->get_by_qcode($p_array['w_categorie_appel']);
+            //  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;
+
+            $tot_bud=$cn->get_value('select b_amount from coprop.budget where 
b_id=$1',array($this->bud_id));
+            if ($tot_bud <=0  ) throw new Exception ("Ce budget a un montant 
de 0 ");
+
+            $this->amount=  bcmul($tot_bud,$this->percent);
+            $this->create_key();
+        } catch (Exception $e)
+        {
+            throw ($e);
+        }
+    }
+}
+?>

Modified: trunk/coprop/include/class_install_plugin.php
===================================================================
--- trunk/coprop/include/class_install_plugin.php       2012-01-12 13:44:16 UTC 
(rev 285)
+++ trunk/coprop/include/class_install_plugin.php       2012-01-12 16:12:17 UTC 
(rev 286)
@@ -54,6 +54,7 @@
        function create_schema()
        {
                $this->cn->exec_sql('create schema coprop');
+                $this->cn->exec_sql("create sequence coprop.appel_fond_id");
        }
 
        function create_card()




reply via email to

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