phpcompta-dev
[Top][All Lists]
Advanced

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

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


From: phpcompta-dev
Subject: [Phpcompta-dev] r271 - in trunk/coprop: . include include/template
Date: Sun, 8 Jan 2012 17:37:04 +0100 (CET)

Author: danydb
Date: 2012-01-08 17:37:03 +0100 (Sun, 08 Jan 2012)
New Revision: 271

Modified:
   trunk/coprop/ajax.php
   trunk/coprop/coprop-javascript.js
   trunk/coprop/include/budget.inc.php
   trunk/coprop/include/class_budget.php
   trunk/coprop/include/lot.inc.php
   trunk/coprop/include/template/budget_list.php
Log:
budget ; create, update and delete

Modified: trunk/coprop/ajax.php
===================================================================
--- trunk/coprop/ajax.php       2012-01-07 23:35:10 UTC (rev 270)
+++ trunk/coprop/ajax.php       2012-01-08 16:37:03 UTC (rev 271)
@@ -1,10 +1,13 @@
 <?php
+
 require_once('coprop-constant.php');
 require_once('class_database.php');
 
 extract($_GET);
 global $cn;
-$html='';$extra='';$ctl='';
+$html = '';
+$extra = '';
+$ctl = '';
 switch ($act)
 {
        case 'addkey':
@@ -13,12 +16,19 @@
        case 'modkey':
                require_once 'include/ajax_mod_key.php';
                break;
-        case 'removekey':
-            require_once 'include/ajax_remove_key.php';
-            break;
-        case 'buddisplay':
-            require_once 'include/ajax_bud_display.php';
-            break;
+       case 'removekey':
+               require_once 'include/ajax_remove_key.php';
+               break;
+       case 'buddisplay':
+               require_once 'include/ajax_bud_display.php';
+               break;
+       case 'budadd':
+               $bud_id=0;
+               require_once 'include/ajax_bud_display.php';
+               break;
+       case 'removebudget':
+               $cn->exec_sql("delete from coprop.budget where 
b_id=$1",array($bud_id));
+               break;
        default:
 
                var_dump($_GET);

Modified: trunk/coprop/coprop-javascript.js
===================================================================
--- trunk/coprop/coprop-javascript.js   2012-01-07 23:35:10 UTC (rev 270)
+++ trunk/coprop/coprop-javascript.js   2012-01-08 16:37:03 UTC (rev 271)
@@ -195,8 +195,7 @@
                                        remove_waiting_box();
                                        $("row"+key_id).style.color="red";
                                        
$("row"+key_id).style.textDecoration="line-through";
-                                        
$("col"+key_id).style.textDecoration="none";
-                                       $("col"+key_id).innerHTML="Effacé";
+                                       $("col"+key_id).innerHTML="";
 
                                        //response.responseText.evalScripts();
                                }
@@ -314,3 +313,72 @@
                alert(e.message);
        }
 }
+function budget_add(dossier,plugin_code,ac)
+{
+       waiting_box();
+       try
+       {
+               var 
queryString="plugin_code="+plugin_code+"&gDossier="+dossier+"&bud_id=0&ac="+ac+"&act=budadd";
+               var action=new Ajax.Request ( 'ajax.php',
+               {
+                       method:'get',
+                       parameters:queryString,
+                       onFailure:null,
+                       onSuccess:function (response)
+                       {
+                               try
+                               {
+                                    remove_waiting_box();
+                                    
$('divbuddetail').innerHTML=response.responseText;
+                                                                       
response.responseText.evalScripts();
+                               }
+                               catch(e)
+                               {
+                                       alert("Réponse Ajax ="+e.message);
+                               }
+                       }
+               }
+               );
+       }
+       catch(e)
+       {
+               alert(e.message);
+       }
+}
+function budget_remove(plugin_code,ac,dossier,bud_id)
+{
+       if (! confirm("Vous voulez effacer ce budget?")) { return;}
+       waiting_box();
+       try
+       {
+               var 
queryString="plugin_code="+plugin_code+"&gDossier="+dossier+"&bud_id="+bud_id+'&ac='+ac+"&act=removebudget";
+               var action=new Ajax.Request ( 'ajax.php',
+               {
+                       method:'get',
+                       parameters:queryString,
+                       onFailure:null,
+                       onSuccess:function (response)
+                       {
+                               try
+                               {
+                                       remove_waiting_box();
+                                       $("row"+bud_id).style.color="red";
+                                       
$("row"+bud_id).style.textDecoration="line-through";
+                                       $("col2"+bud_id).innerHTML="";
+                                       $("col1"+bud_id).innerHTML="";
+
+                                       //response.responseText.evalScripts();
+                               }
+                               catch(e)
+                               {
+                                       alert("Réponse Ajax ="+e.message);
+                               }
+                       }
+               }
+               );
+       }
+       catch(e)
+       {
+               alert(e.message);
+       }
+}
\ No newline at end of file

Modified: trunk/coprop/include/budget.inc.php
===================================================================
--- trunk/coprop/include/budget.inc.php 2012-01-07 23:35:10 UTC (rev 270)
+++ trunk/coprop/include/budget.inc.php 2012-01-08 16:37:03 UTC (rev 271)
@@ -7,12 +7,18 @@
 require_once 'class_budget.php';
 $bud=new Budget();
 
-if ( isset ($_POST['budget_update']))
+if ( isset ($_POST['bud_update']))
 {
-       $bud->save();
+       $bud->save($_POST);
 }
 
 
 
+echo '<div id="bud_list" class="content">';
+$bud->to_list();
+echo HtmlInput::button("bud_add_bt","Ajout 
Budget","onclick=\"budget_add('".$_REQUEST['gDossier']."','".$_REQUEST['plugin_code']."','".$_REQUEST['ac']."')\"");
+echo '</div>';
+?>
+<div id="divbuddetail">
 
-$bud->to_list();
\ No newline at end of file
+</div>
\ No newline at end of file

Modified: trunk/coprop/include/class_budget.php
===================================================================
--- trunk/coprop/include/class_budget.php       2012-01-07 23:35:10 UTC (rev 
270)
+++ trunk/coprop/include/class_budget.php       2012-01-08 16:37:03 UTC (rev 
271)
@@ -58,10 +58,10 @@
 
             if ( ! isset ($this->b_id)|| trim($this->b_id)=='')
                     throw new Exception ("Aucun budget demandé");
-                       $this->load();
                        $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);
@@ -80,7 +80,8 @@
                        echo 
HtmlInput::request_to_hidden(array('gDossier','ac','plugin_code','sa'));
                        require_once 'template/budget.php';
 
-            $array=$cn->get_array("select 
bt_id,bt_amount,f_id,vw_name,quick_code,cr_name,cr_id
+            $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)
@@ -92,6 +93,9 @@
                        $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;
@@ -126,7 +130,8 @@
                 $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)?0:HtmlInput::hidden("bt_id[]",$array[$i]["bt_id"]);
+                
$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;
@@ -135,7 +140,7 @@
                 $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"]=$f_card_label;
+                $a_input[$i]["card_label"]=$label->input();
 
                 $a_input[$i]['key']=$ikey->input();
 
@@ -146,10 +151,165 @@
         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;
+               }
+
+       }
+}
 ?>

Modified: trunk/coprop/include/lot.inc.php
===================================================================
--- trunk/coprop/include/lot.inc.php    2012-01-07 23:35:10 UTC (rev 270)
+++ trunk/coprop/include/lot.inc.php    2012-01-08 16:37:03 UTC (rev 271)
@@ -107,7 +107,7 @@
 /**
  * @todo ajouter tri
  */
-$a_copro=$cn->get_array($sql,array($g_copro_parameter->categorie_coprop));
+/*$a_copro=$cn->get_array($sql,array($g_copro_parameter->categorie_coprop));
 
 $sql_lot=$cn->prepare ("lot","select f_id,
        (select ad_value from fiche_detail where f_id=l_fiche_id and ad_id=1) 
as lot_name,
@@ -115,7 +115,7 @@
         (select ad_value from fiche_detail where f_id=l_fiche_id and ad_id=9) 
as lot_desc
        from fiche where f_id in ( select f_id from fiche_detail where ad_id=$1 
and ad_value=$2)
        and fd_id=$3");
-
+*/
 echo $f_add_button->input();
 
 

Modified: trunk/coprop/include/template/budget_list.php
===================================================================
--- trunk/coprop/include/template/budget_list.php       2012-01-07 23:35:10 UTC 
(rev 270)
+++ trunk/coprop/include/template/budget_list.php       2012-01-08 16:37:03 UTC 
(rev 271)
@@ -10,16 +10,19 @@
         <th> Nom </th>
         <th> Date début </th>
         <th> Date Fin </th>
-        <th> Montant </th>
+        <th style="text-align: right"> Montant </th>
     </tr>
 <?
 for ($i=0;$i<count($array);$i++):
     $class=($i%2==0)?' class="evend" ':' class="odd" ';
-    $str_js=sprintf(" onclick=\"budget_detail('%s','%s','%s','%s')\" ",
+    $str_js=sprintf(" onclick=\"budget_detail('%s','%s','%s','%s');  \"",
             
$_REQUEST['plugin_code'],$_REQUEST['ac'],$_REQUEST['gDossier'],$array[$i]['b_id']);
     $js=HtmlInput::anchor("Détail","",$str_js);
+       $str_js_del=sprintf(" onclick=\"budget_remove('%s','%s','%s','%s');\" ",
+            
$_REQUEST['plugin_code'],$_REQUEST['ac'],$_REQUEST['gDossier'],$array[$i]['b_id']);
+    $js_del=HtmlInput::anchor("Effacer","",$str_js_del);
 ?>
-    <tr <?=$class?> >
+    <tr id="row<?=$array[$i]['b_id']?>" <?=$class?> >
         <td>
             <?=$array[$i]['b_name']?>
         </td>
@@ -29,18 +32,18 @@
         <td>
             <?=$array[$i]['str_end']?>
         </td>
-        <td>
+        <td CLASS="num">
             <?=nbm($array[$i]['b_amount'])?>
         </td>
-        <td>
+        <td  id="col1<?=$array[$i]['b_id']?>">
             <?=$js?>
         </td>
-    </tr>  
+        <td  id="col2<?=$array[$i]['b_id']?>">
+            <?=$js_del?>
+        </td>
+    </tr>
 <?
 endfor;
 ?>
-    
+
 </table>
-<div id="divbuddetail">
-
-</div>
\ No newline at end of file




reply via email to

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