phpcompta-dev
[Top][All Lists]
Advanced

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

[Phpcompta-dev] r5552 - phpcompta/tags/rel670/include


From: phpcompta-dev
Subject: [Phpcompta-dev] r5552 - phpcompta/tags/rel670/include
Date: Thu, 28 Nov 2013 20:55:34 +0100 (CET)

Author: danydb
Date: 2013-11-28 20:55:34 +0100 (Thu, 28 Nov 2013)
New Revision: 5552

Modified:
   phpcompta/tags/rel670/include/class_stock.php
   phpcompta/tags/rel670/include/class_stock_goods.php
   phpcompta/tags/rel670/include/stock_state.inc.php
Log:
Correct stock insert and reporting

Modified: phpcompta/tags/rel670/include/class_stock.php
===================================================================
--- phpcompta/tags/rel670/include/class_stock.php       2013-11-28 19:55:32 UTC 
(rev 5551)
+++ phpcompta/tags/rel670/include/class_stock.php       2013-11-28 19:55:34 UTC 
(rev 5552)
@@ -259,6 +259,18 @@
        function build_tmp_table($p_array)
        {
                global $cn,$g_user;
+                // exercice 
+                if (isset ($p_array['state_exercice']))
+                {
+                    $periode=new Periode($cn);
+                    $date=  format_date($p_array['state_exercice'], 
'YYYY-MM-DD');
+                    $periode->find_periode($date);
+                    
+                } else {
+                    $periode_id=$g_user->get_periode();
+                    $periode=new Periode($cn,$periode_id);
+                }
+                $periode->load();
                $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 days' ");
                $cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)", 
array($tmp_id));
@@ -266,16 +278,6 @@
                // get all readable repository
                $a_repository = $g_user->get_available_repository('R');
 
-
-               $end_date = $cn->get_value("select 
to_char(max(p_end),'DD.MM.YYYY') from parm_periode");
-               if (isset($p_array['state_exercice']))
-               {
-                       $tmp_date=  
format_date($p_array['state_exercice'],'YYYY-MM-DD','DD.MM.YYYY');
-                       if (isDate($tmp_date) == $tmp_date)
-                       {
-                               $end_date = $tmp_date;
-                       }
-               }
                // From ACH : IN
                $sql_repo_detail = "
                        insert into 
tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
@@ -284,13 +286,13 @@
                                where
                                        sg_type='d'
                                        and j_id is not null
-                                       and j_id in (select j_id from jrnx 
where  j_date <= to_date($2,'DD.MM.YYYY'))
+                                       and j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
                                        and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
                                        group by r_id,trim(sg_code),f_id
                        ";
 
                // From VEN : out
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$end_date));
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
                $sql_repo_detail = "
                                insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
                                select $tmp_id,trim(sg_code) , 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
@@ -298,11 +300,11 @@
                                where
                                        sg_type='c'
                                        and sg.j_id is not null
-                                       and sg.j_id in (select j_id from jrnx 
where  j_date <= to_date($2,'DD.MM.YYYY'))
+                                       and sg.j_id in (select j_id from jrnx 
where  j_tech_per in (select p_id from parm_periode where p_exercice=$2))
                                        and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
                                        group by r_id,trim(sg_code),f_id
                        ";
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$end_date));
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
 
                // From INV  IN
                $sql_repo_detail = "
@@ -312,13 +314,13 @@
                                where
                                        sg_type='d'
                                        and j_id is null
-                                       and sg_tech_date <= 
to_date($2,'DD.MM.YYYY')
+                                       and sg_date >= ( select min(p_start) 
from parm_periode where p_exercice=$2)
+                                       and sg_date <= ( select max(p_end) from 
parm_periode where p_exercice=$2)
                                         and sg.r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
                                        group by r_id,trim(sg_code),f_id
                        ";
-
                // From INV: OUT
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$end_date));
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
                $sql_repo_detail = "
                                insert into 
tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
                                select $tmp_id,trim(sg_code), 
coalesce(sum(sg_quantity),0) as qout,r_id,f_id
@@ -327,10 +329,10 @@
                                        sg_type='c'
                                        and j_id is null
                                         and r_id  in (select r_id from 
profile_sec_repository where p_id=$1)
-                                       and sg_tech_date  <= 
to_date($2,'DD.MM.YYYY')
+                                       and sg_date  <= to_date($2,'DD.MM.YYYY')
                                        group by r_id,trim(sg_code),f_id
                        ";
-               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$end_date));
+               $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), 
$periode->p_exercice));
                return $tmp_id;
        }
 

Modified: phpcompta/tags/rel670/include/class_stock_goods.php
===================================================================
--- phpcompta/tags/rel670/include/class_stock_goods.php 2013-11-28 19:55:32 UTC 
(rev 5551)
+++ phpcompta/tags/rel670/include/class_stock_goods.php 2013-11-28 19:55:34 UTC 
(rev 5552)
@@ -135,9 +135,17 @@
                                if ($p_array['sg_quantity' . $i] != 0 &&
                                                trim($p_array['sg_code' . $i]) 
!= '')
                                {
+                                        $stock=  
strtoupper(trim($p_array['sg_code' . $i]));
                                        $fiche=new Fiche($cn);
                                        $fiche->get_by_qcode($p_array['sg_code' 
. $i]);
-                                       
$stock=$fiche->strAttribut(ATTR_DEF_STOCK);
+                                       /*
+                                         * check if code stock does exist
+                                         */
+                                        $count=$cn->get_value('select count(*) 
from fiche_detail where ad_id=$1 and ad_value=$2',
+                                                array(ATTR_DEF_STOCK,$stock));
+                                        if ( $count==0) {
+                                            throw new Exception("Code stock 
inexistant");
+                                        }
                                        $a->f_id=$fiche->id;
                                        $a->sg_code = $stock;
                                        $a->sg_quantity = 
abs($p_array['sg_quantity' . $i]);

Modified: phpcompta/tags/rel670/include/stock_state.inc.php
===================================================================
--- phpcompta/tags/rel670/include/stock_state.inc.php   2013-11-28 19:55:32 UTC 
(rev 5551)
+++ phpcompta/tags/rel670/include/stock_state.inc.php   2013-11-28 19:55:34 UTC 
(rev 5552)
@@ -35,7 +35,12 @@
 // Get type = table or list
 $iexercice=new ISelect('state_exercice');
 $iexercice->value=$cn->make_array("select  max(p_end) as date_end, p_exercice 
from parm_periode  group by p_exercice order by 2 desc");
-$iexercice->selected=(isset($_GET['state_exercice']))?$_GET['state_exercice']:"";
+$per=new Periode($cn,$g_user->get_periode());
+$per->load();
+$date_limit=$per->limit_year($per->p_exercice);
+$last_day=$per->last_day($date_limit['end']);
+$last_day=format_date($last_day,'DD.MM.YYYY','YYYY-MM-DD');
+$iexercice->selected=(isset($_GET['state_exercice']))?$_GET['state_exercice']:$last_day;
 
 $presentation=new ISelect("present");
 $presentation->value=array (



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