phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r4894 - phpcompta/trunk/include


From: phpcompta-dev
Subject: [Phpcompta-dev] r4894 - phpcompta/trunk/include
Date: Thu, 14 Jun 2012 15:35:15 +0200 (CEST)

Author: danydb
Date: 2012-06-14 15:35:15 +0200 (Thu, 14 Jun 2012)
New Revision: 4894

Modified:
   phpcompta/trunk/include/class_acc_ledger_purchase.php
   phpcompta/trunk/include/class_html_input.php
   phpcompta/trunk/include/class_user.php
   phpcompta/trunk/include/user_common.php
Log:
Add HtmlInput::select_stock
Add function User::can_write_action and User::can_write_repo
Insert into the stock with repository
Let select the stock in Acc_Ledger_Purchase::confirm

Modified: phpcompta/trunk/include/class_acc_ledger_purchase.php
===================================================================
--- phpcompta/trunk/include/class_acc_ledger_purchase.php       2012-06-14 
12:24:10 UTC (rev 4893)
+++ phpcompta/trunk/include/class_acc_ledger_purchase.php       2012-06-14 
13:35:15 UTC (rev 4894)
@@ -471,9 +471,9 @@
 
                 // always save quantity but in withStock we can find
                 // what card need a stock management
+                if ( $g_parameter->MY_STOCK='Y')
+                    
InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ;
 
-                
InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ;
-
                 if ( $g_parameter->MY_ANALYTIC != "nu" )
                 {
                     // for each item, insert into operation_analytique */
@@ -1504,8 +1504,10 @@
             $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
 
         }
-               if ( ! $p_summary ) $r.=$this->extra_info();
-               if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
+       if ( ! $p_summary ) 
+            $r.=$this->extra_info();
+        
+       if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
         {
             $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
             $r.=HtmlInput::hidden('acompte',$acompte);
@@ -1518,8 +1520,12 @@
             $r.='<br>';
         }
         // check for upload piece
-
-
+        
+       // Show the available repository
+        if ( $g_parameter->MY_STOCK=='Y')
+        {
+           $r.=HtmlInput::select_stock('repo','W');
+        }
         return $r;
     }
 

Modified: phpcompta/trunk/include/class_html_input.php
===================================================================
--- phpcompta/trunk/include/class_html_input.php        2012-06-14 12:24:10 UTC 
(rev 4893)
+++ phpcompta/trunk/include/class_html_input.php        2012-06-14 13:35:15 UTC 
(rev 4894)
@@ -616,4 +616,34 @@
                   $p_url,$p_js,$p_text);
           return $str;
       }
+      /**
+       *Create an ISelect object containing the available repository for 
reading
+       * or writing
+       * @global $g_user
+       * @param $p_cn db object
+       * @param $p_name name of the select
+       * @param $p_mode is 'R' for reading, 'W' for writinh
+       * @return ISelect
+       * @throws Exception if p_mode is wrong
+       */
+      static function select_stock( $p_cn, $p_name,$p_mode)
+      {
+          global $g_user;
+          if ( in_array($p_mode,array('R','W') ) )
+          {
+              throw  new Exception  (__FILE__.":".__LINE__." $p_mode 
invalide");
+          }
+          $profile=$g_user->get_profile();
+          $sel=new ISelect($p_name);
+          
+          $write=($p_mode=='W')?"ur_right='W' and ":"";
+          
+          $sel->value=$p_cn->make_array("
+                select r_id,r_name from stock_repository
+                where 
+                $write p_id=$1
+                order by 2
+              ",array($profile));
+          return $sel;
+      }
 }
\ No newline at end of file

Modified: phpcompta/trunk/include/class_user.php
===================================================================
--- phpcompta/trunk/include/class_user.php      2012-06-14 12:24:10 UTC (rev 
4893)
+++ phpcompta/trunk/include/class_user.php      2012-06-14 13:35:15 UTC (rev 
4894)
@@ -1024,14 +1024,21 @@
                        $this->db->exec_sql("update profile_user set p_id=$1 
where user_name=$2", array($p_id, $this->login));
                }
        }
-
+        /**
+         *return the profile (p_id)
+         * @return profile.p_id
+         */
        function get_profile()
        {
                $profile = $this->db->get_value("select p_id from profile_user 
where
                                user_name=$1", array($this->login));
                return $profile;
        }
-
+        /**
+         *Check if the profile of the user can write for this profile
+         * @param  $dtoc action_gestion.ag_id
+         * @return true if he can write otherwise false
+         */
        function can_write_action($dtoc)
        {
                $profile = $this->get_profile();
@@ -1042,6 +1049,11 @@
                return true;
        }
 
+        /**
+         *Check if the profile of the user can write for this profile
+         * @param  $dtoc action_gestion.ag_id
+         * @return true if he can write otherwise false
+         */
        function can_read_action($dtoc)
        {
                $profile = $this->get_profile();
@@ -1051,6 +1063,42 @@
                        return false;
                return true;
        }
+        /**
+         *Check if the profile of the user can write for this repository
+         * @param  $p_repo stock_repository.r_id
+         * @return true if he can write otherwise false
+         */
+        function can_write_repo($p_repo)
+        {
+            $profile=$this->get_profile();
+            $r=$this->db->get_value("select count(*)
+                from user_sec_repository 
+                where 
+                r_id=$1
+                and p_id =$2 
+                and ur_right='W'",array($p_repo,$profile));
+            if ( $r==0)
+                return false;
+            return true;
+        }
+       /**
+         *Check if the profile of the user can read for this repository
+         * @param  $p_repo stock_repository.r_id
+         * @return true if he read write otherwise false
+         */
+        function can_read_repo($p_repo)
+        {
+            $profile=$this->get_profile();
+            $r=$this->db->get_value("select count(*)
+                from user_sec_repository 
+                where 
+                r_id=$1
+                and p_id =$2 
+               ",array($p_repo,$profile));
+            if ( $r==0)
+                return false;
+            return true;
+        }
 
 }
 

Modified: phpcompta/trunk/include/user_common.php
===================================================================
--- phpcompta/trunk/include/user_common.php     2012-06-14 12:24:10 UTC (rev 
4893)
+++ phpcompta/trunk/include/user_common.php     2012-06-14 13:35:15 UTC (rev 
4894)
@@ -44,38 +44,45 @@
  * \param $p_j_id the j_id
  * \param $p_good the goods
  * \param $p_quant  quantity
- * \param $p_type c for credit or d for debit
+ * \param $p_type c for SALE or d for PURCHASE
  *
- * \return none
+ * \return $res of the insert or false if something gets wrong
  * \note Link to jrn gives the date
  */
-function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)
+function InsertStockGoods($p_cn, $p_j_id, $p_good, $p_quant, $p_type,$p_depot)
 {
     global $g_user;
+    if ( $g_user->can_write_repo($p_depo) == false ) 
+        return false;
+
     // Retrieve the good account for stock
-    $code=new Fiche($p_cn);
+    $code = new Fiche($p_cn);
     $code->get_by_qcode($p_good);
-    $code_marchandise=$code->strAttribut(ATTR_DEF_STOCK);
-    $p_good=sql_string($p_good);
-    $sql="select f_id from vw_poste_qcode where j_qcode=upper('$p_good')";
-    $Res=$p_cn->exec_sql($sql);
-    $r=Database::fetch_array($Res,0);
-    $f_id=$r['f_id'];
-    $exercice=$g_user->get_exercice();
-    if ( $exercice == 0 ) throw new Exception ('Annee invalide erreur');
+    $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
+    if ( $code_marchandise == NOTFOUND ) 
+        return false;
+    
+    $exercice = $g_user->get_exercice();
+    
+    if ($exercice == 0)
+        throw new Exception('Annee invalide erreur');
 
-
-    $Res=$p_cn->exec_sql("insert into stock_goods (
+    $Res = $p_cn->exec_sql("insert into stock_goods (
                          j_id,
                          f_id,
                          sg_code,
                          sg_quantity,
-                         sg_type,sg_exercice ) values (
-                         $p_j_id,
-                         $f_id,
-                         '$code_marchandise',
-                         $p_quant, '$p_type',$exercice)
-                         ");
+                         sg_type,sg_exercice,r_id ) values 
($1,$2,$3,$4,$5,$6,$7)", 
+            array(
+                    $p_j_id,
+                    $code->id,
+                    $code_marchandise,
+                    $p_quant, 
+                    $p_type,
+                    $exercice,
+                    $p_depot
+                )
+            );
     return $Res;
 }
 



---
PhpCompta est un logiciel de comptabilité libre en ligne (full web)
Projet opensource http://www.phpcompta.eu



reply via email to

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