phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r4918 - in phpcompta/trunk: contrib/document_test includ


From: phpcompta-dev
Subject: [Phpcompta-dev] r4918 - in phpcompta/trunk: contrib/document_test include include/template sql
Date: Sun, 17 Jun 2012 01:42:19 +0200 (CEST)

Author: danydb
Date: 2012-06-17 01:42:17 +0200 (Sun, 17 Jun 2012)
New Revision: 4918

Added:
   phpcompta/trunk/contrib/document_test/all_tags.odt
   phpcompta/trunk/include/stock_state.inc.php
   phpcompta/trunk/include/template/stock_summary.php
Modified:
   phpcompta/trunk/include/class_stock.php
   phpcompta/trunk/include/class_user.php
   phpcompta/trunk/sql/upgrade.sql
Log:
Start Stock_Summary

Added: phpcompta/trunk/contrib/document_test/all_tags.odt
===================================================================
(Binary files differ)


Property changes on: phpcompta/trunk/contrib/document_test/all_tags.odt
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: phpcompta/trunk/include/class_stock.php
===================================================================
--- phpcompta/trunk/include/class_stock.php     2012-06-16 19:02:45 UTC (rev 
4917)
+++ phpcompta/trunk/include/class_stock.php     2012-06-16 23:42:17 UTC (rev 
4918)
@@ -406,6 +406,53 @@
                return $sql . $where . $clause;
        }
 
+       function summary($p_array)
+       {
+               global $cn, $g_user;
+               $tmp_id=$cn->get_next_seq("public.tmp_stockgood_s_id_seq");
+               $cn->exec_sql("delete from tmp_stockgood where s_date < now() - 
interval '2 hours' ");
+               $cn->exec_sql("insert into tmp_stockgood(s_id) values 
($1)",array($tmp_id));
+
+               // get all readable repository
+               $a_repository=$g_user->get_available_repository('R');
+
+               // All the stock card
+               $sql_repo_detail="
+                       insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,s_qout,r_id)
+
+               with fiche_stock as (select distinct ad_value from fiche_detail 
where ad_id=19 and coalesce(ad_value,'') != '') ,
+                               stock_in as (select 
coalesce(sum(sg_quantity),0) as qin,r_id,sg_code from stock_goods where 
sg_type='c'
+                               and (
+                                       (j_id is not null and j_id in (select 
j_id from jrnx where  j_date <= '2010-12-31')
+                                       or sg_tech_date <= '2010-12-31')
+                               )
+                               group by r_id,sg_code) ,
+                               stock_out as    (select 
coalesce(sum(sg_quantity),0) as qout ,r_id,sg_code from stock_goods
+                               where sg_type='d'
+                               and (
+                                       (j_id is not null and j_id in (select 
j_id from jrnx where  j_date <= '2010-12-31')
+                                       or sg_tech_date <= '2010-12-31')
+                               )
+                               group by r_id,sg_code)
+                               select distinct
+                                       $tmp_id,
+                                       coalesce(si.sg_code,so.sg_code),
+                                       coalesce(qin,0) as qin,
+                                       coalesce(qout,0) as qout,
+                                       sg.r_id
+                                       from
+                                       stock_goods as sg
+                                       left join stock_in as si on ( 
sg.r_id=si.r_id)
+                                       full join stock_out as so on 
(si.sg_code=so.sg_code and sg.r_id=so.r_id)
+                               where
+                               si.sg_code is not null or so.sg_code is not null
+                                and sg.r_id  in (select r_id from 
user_sec_repository where p_id=$1)
+
+                       ";
+               $cn->exec_sql($sql_repo_detail,array($g_user->get_profile()));
+               $a_code=$cn->get_array("select distinct sg_code from 
tmp_stockgood_detail where s_id=$1",array($tmp_id));
+               require_once 'template/stock_summary.php' ;
+       }
 }
 
 ?>

Modified: phpcompta/trunk/include/class_user.php
===================================================================
--- phpcompta/trunk/include/class_user.php      2012-06-16 19:02:45 UTC (rev 
4917)
+++ phpcompta/trunk/include/class_user.php      2012-06-16 23:42:17 UTC (rev 
4918)
@@ -788,7 +788,40 @@
 
                return $isAdmin;
        }
-
+       /**
+        address@hidden return array of available repository
+        *
+        * @param $p_access  R for read W for write
+        * @return an array
+        */
+       function get_available_repository($p_access='R')
+       {
+                $profile=$this->get_profile();
+                $r=array();
+               if ($p_access=='R')
+               {
+                       $r=$this->db->get_array("select u.r_id,r_name
+                from
+                                       user_sec_repository as u
+                                       join stock_repository as s 
on(u.r_id=s.r_id)
+                where
+                p_id =$1
+                and ur_right='W'
+                               order by 2
+                               ",array($profile));
+               }
+               if ($p_access == 'W')
+               {
+                        $r=$this->db->get_array("select u.r_id,r_name
+                from
+                                       user_sec_repository as u
+                                       join stock_repository as s 
on(u.r_id=s.r_id)
+                where
+                p_id =$1 order by 2
+               ",array($profile));
+               }
+               return $r;
+       }
        /* !
         * \brief return an array with all the users who can access $p_dossier 
including the global admin. The user
         * must be activated
@@ -1072,10 +1105,10 @@
         {
             $profile=$this->get_profile();
             $r=$this->db->get_value("select count(*)
-                from user_sec_repository 
-                where 
+                from user_sec_repository
+                where
                 r_id=$1
-                and p_id =$2 
+                and p_id =$2
                 and ur_right='W'",array($p_repo,$profile));
             if ( $r==0)
                 return false;
@@ -1090,10 +1123,10 @@
         {
             $profile=$this->get_profile();
             $r=$this->db->get_value("select count(*)
-                from user_sec_repository 
-                where 
+                from user_sec_repository
+                where
                 r_id=$1
-                and p_id =$2 
+                and p_id =$2
                ",array($p_repo,$profile));
             if ( $r==0)
                 return false;

Added: phpcompta/trunk/include/stock_state.inc.php
===================================================================
--- phpcompta/trunk/include/stock_state.inc.php                         (rev 0)
+++ phpcompta/trunk/include/stock_state.inc.php 2012-06-16 23:42:17 UTC (rev 
4918)
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show the state of the repository
+ *
+ */
+global $cn,$g_parameter,$g_user;
+require_once 'class_stock.php';
+
+$stock=new Stock();
+
+$stock->summary($_GET);
+
+?>

Added: phpcompta/trunk/include/template/stock_summary.php
===================================================================
--- phpcompta/trunk/include/template/stock_summary.php                          
(rev 0)
+++ phpcompta/trunk/include/template/stock_summary.php  2012-06-16 23:42:17 UTC 
(rev 4918)
@@ -0,0 +1,133 @@
+<?php
+/*
+ *   This file is part of PhpCompta.
+ *
+ *   PhpCompta is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   PhpCompta is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder address@hidden
+
+/**
+ * @file
+ * @brief show State of the stock
+ *
+ */
+?>
+<div class="content">
+<table class="result">
+       <tr>
+               <th>
+                       Code Stock
+               </th>
+               <? for ($i = 0; $i < count($a_repository); $i++):?>
+                       <th>
+                               <?=h( $a_repository[$i]['r_name'])?>
+                       </th>
+               <? endfor;?>
+                       <th>
+                               Total
+                       </th>
+       </tr>
+       <?
+       for ($x = 0; $x < count($a_code); $x++):
+               $class=($x%2==0)?' class="odd" ':' class="even" ';
+               ?>
+
+               <tr <?=$class?> >
+                       <td>
+                               <?= $a_code[$x]['sg_code']?>
+                       </td>
+                       <?
+                       $n_in=0;$n_out=0;
+                       for ($e = 0; $e < count($a_repository); $e++):
+
+                               $array = $cn->get_array("select * from 
tmp_stockgood_detail where r_id=$1 and sg_code=$2", 
array($a_repository[$e]['r_id'], $a_code[$x]['sg_code']));
+                               ?>
+                       <td>
+                               <?
+                                       if (count($array)==0):
+                                               echo 0;
+                                       else:
+                                               $n_in+=$array[0]['s_qin'];
+                                               $n_out+=$array[0]['s_qout'];
+                                               ?>
+                                               <table>
+                                                       <tr>
+                                                               <td>
+                                                                       IN  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm($array[0]['s_qin'])?>
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td>
+                                                                       OUT  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm($array[0]['s_qout'])?>
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td>
+                                                                       DIFF  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm((bcsub($array[0]['s_qin'],$array[0]['s_qout'])))?>
+                                                               </td>
+                                                       </tr>
+                                               </table>
+                                               <?
+                                       endif;
+                               ?>
+                       </td>
+                               <?
+                       endfor;  // loop e
+                       ?>
+                       <td>
+<table>
+                                                       <tr>
+                                                               <td>
+                                                                       IN  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm($n_in)?>
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td>
+                                                                       OUT  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm($n_out)?>
+                                                               </td>
+                                                       </tr>
+                                                       <tr>
+                                                               <td>
+                                                                       DIFF  :
+                                                               </td>
+                                                               <td class="num">
+                                                                       
<?=nbm((bcsub($n_in,$n_out)))?>
+                                                               </td>
+                                                       </tr>
+                                               </table>
+                       </td>
+               </tr>
+               <?
+       endfor; // loop x
+       ?>
+</table>
+</div>
\ No newline at end of file

Modified: phpcompta/trunk/sql/upgrade.sql
===================================================================
--- phpcompta/trunk/sql/upgrade.sql     2012-06-16 19:02:45 UTC (rev 4917)
+++ phpcompta/trunk/sql/upgrade.sql     2012-06-16 23:42:17 UTC (rev 4918)
@@ -320,4 +320,8 @@
 
 drop function migrate_stock();
 
-update attr_def set ad_type='card', ad_extra='[sql] fd_id = 500000 ' where 
ad_id=19;
\ No newline at end of file
+update attr_def set ad_type='card', ad_extra='[sql] fd_id = 500000 ' where 
ad_id=19;
+
+create table tmp_stockgood (s_id bigserial primary key,s_date timestamp 
default now());
+create table tmp_stockgood_detail(d_id bigserial primary key,s_id bigint 
references tmp_stockgood(s_id) on delete cascade,
+sg_code text,s_qin numeric(20,4),s_qout numeric(20,4),r_id bigint);
\ No newline at end of file



---
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]