diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 924a58697..89f9db0bc 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -1482,7 +1482,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger $r.=''.td(_('Total TVAC')).td(hb(nbm($tot)),'class="num"'); $r.=''; } else { - $r.='
Total '.nbm(hb($tot)); + $r.='
Total '.hb(nbm($tot)); } $r.='

'; /* Add hidden */ diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index dcf9934d3..5b3d602ac 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -809,7 +809,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { $r.=''.td(_('Total TVAC')).td(hb(nbm($tot)),'class="num"'); $r.=''; } else { - $r.='
Total '.nbm(hb($tot)); + $r.='
Total '.hb(nbm($tot)); } $r.='

'; if (!$p_summary) { diff --git a/include/class_periode.php b/include/class_periode.php index 60371e1b2..e13771a91 100644 --- a/include/class_periode.php +++ b/include/class_periode.php @@ -415,7 +415,7 @@ class Periode */ function load() { - + if ($this->p_id == '') $this->p_id=-1; $row=$this->cn->get_array("select p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1", array($this->p_id)); if ($row == null ) return -1; diff --git a/include/class_stock.php b/include/class_stock.php index 553884a8b..fa18c8386 100644 --- a/include/class_stock.php +++ b/include/class_stock.php @@ -259,6 +259,18 @@ class Stock extends Stock_Sql 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 @@ class Stock extends Stock_Sql // 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 @@ class Stock extends Stock_Sql 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 @@ class Stock extends Stock_Sql 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 @@ class Stock extends Stock_Sql 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 @@ class Stock extends Stock_Sql 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; } diff --git a/include/class_stock_goods.php b/include/class_stock_goods.php index e8ccaeccd..68abf44fc 100644 --- a/include/class_stock_goods.php +++ b/include/class_stock_goods.php @@ -135,9 +135,17 @@ class Stock_Goods extends Stock_Goods_Sql 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]); diff --git a/include/export_stock_resume_list.php b/include/export_stock_resume_list.php index 829ca1b06..e74250f0b 100644 --- a/include/export_stock_resume_list.php +++ b/include/export_stock_resume_list.php @@ -28,8 +28,9 @@ */ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis'); require_once 'class_stock.php'; +global $cn; // var_dump($_GET); -$stock=new Stock(); +$stock=new Stock($cn); $tmp_id = $stock->build_tmp_table($_GET); header('Pragma: public'); diff --git a/include/periode.inc.php b/include/periode.inc.php index f445c3256..c76270ca2 100644 --- a/include/periode.inc.php +++ b/include/periode.inc.php @@ -89,7 +89,13 @@ if ( $action== "delete_per" ) } else { - $Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per"); + $count=$cn->get_value("select count(*) from parm_periode;"); + if ( $count > 1 ) { + $Res=$cn->exec_sql("delete from parm_periode where p_id=$p_per"); + } + { + alert(' Désolé mais vous devez avoir au moins une période'); + } } $choose="yes"; } diff --git a/include/stock_state.inc.php b/include/stock_state.inc.php index 8e4e5ed29..7ebe02ee0 100644 --- a/include/stock_state.inc.php +++ b/include/stock_state.inc.php @@ -35,7 +35,12 @@ require_once 'class_stock.php'; // 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 (