diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php
index 3f75da96c..d731d80df 100644
--- a/include/class_acc_ledger_purchase.php
+++ b/include/class_acc_ledger_purchase.php
@@ -472,7 +472,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// 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',$repo) ;
if ( $g_parameter->MY_ANALYTIC != "nu" )
{
@@ -1491,6 +1491,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
/* Paid by */
/* if the paymethod is not 0 and if a quick code is given */
+
for ($i=0;$i < $nb_item;$i++)
{
$r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
@@ -1504,9 +1505,21 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
}
- if ( ! $p_summary )
+ if ( ! $p_summary )
$r.=$this->extra_info();
-
+ if ($g_parameter->MY_STOCK == 'Y')
+ {
+ $sel = HtmlInput::select_stock($this->db, 'repo', 'W');
+ $sel->readOnly = $p_summary;
+ if ($p_summary == true)
+ $sel->selected = $repo;
+ $r.="
";
+ $r.='Dépôt
';
+ $r.="
Dans le dépôt : ";
+ $r.=$sel->input();
+ $r.='
';
+ $r.='
';
+ }
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});
@@ -1515,17 +1528,13 @@ class Acc_Ledger_Purchase extends Acc_Ledger
$r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
$fname = new Fiche($this->db);
$fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
+ $r.="";
$r.='' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
- " ".$fname->getName() ." ". _('Déduction acompte ').h($acompte).'
';
+ " ".$fname->getName() ." ". _('Déduction acompte ').h($acompte).'';
$r.='
';
}
// check for upload piece
-
- // Show the available repository
- if ( $g_parameter->MY_STOCK=='Y')
- {
- $r.=HtmlInput::select_stock('repo','W');
- }
+
return $r;
}
diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php
index d0079220c..cac6e5707 100644
--- a/include/class_acc_ledger_sold.php
+++ b/include/class_acc_ledger_sold.php
@@ -353,7 +353,8 @@ class Acc_Ledger_Sold extends Acc_Ledger
// always save quantity but in withStock we can find
// what card need a stock management
- InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'c') ;
+ if ( $g_parameter->MY_STOCK='Y')
+ InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'c',$repo) ;
if ( $g_parameter->MY_ANALYTIC != "nu" )
{
@@ -883,6 +884,20 @@ class Acc_Ledger_Sold extends Acc_Ledger
$e_mp=(isset($e_mp))?$e_mp:0;
$r.=HtmlInput::hidden('e_mp',$e_mp);
+ // Show the available repository
+ if ($g_parameter->MY_STOCK == 'Y')
+ {
+ $sel = HtmlInput::select_stock($this->db, 'repo', 'W');
+ $sel->readOnly = $p_summary;
+ if ($p_summary == true)
+ $sel->selected = $repo;
+ $r.="";
+ $r.='Dépôt
';
+ $r.="
Dans le dépôt : ";
+ $r.=$sel->input();
+ $r.='
';
+ $r.='
';
+ }
/* Paid by */
/* if the paymethod is not 0 and if a quick code is given */
if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
@@ -894,8 +909,9 @@ class Acc_Ledger_Sold extends Acc_Ledger
$fname=new Fiche($this->db);
$fname->get_by_qcode(${'e_mp_qcode_'.$e_mp});
+ $r.="";
$r.=''."Payé par ".${'e_mp_qcode_'.$e_mp}.
- " ".$fname->getName().' '._('Déduction acompte ').h($acompte).'
';
+ " ".$fname->getName().' '._('Déduction acompte ').h($acompte).'';
$r.='
';
}
diff --git a/include/class_document.php b/include/class_document.php
index 1d15af8f2..2c000765b 100644
--- a/include/class_document.php
+++ b/include/class_document.php
@@ -1078,6 +1078,7 @@ class Document
case 'ACOMPTE':
if ( isset($p_array['acompte']))
return $p_array['acompte'];
+ return "0";
break;
}
/*
@@ -1085,7 +1086,7 @@ class Document
*/
if (preg_match('/^ATTR/', $p_tag) == 1)
{
- // Retrieve f_id
+ // Retrieve f_id
if ( isset ($p_array['e_march'.$counter]))
{
$id = $p_array['e_march' . $counter];
@@ -1098,7 +1099,7 @@ class Document
if (preg_match('/^BENEFATTR/', $p_tag) == 1)
{
$qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
- // Retrieve f_id
+ // Retrieve f_id
$r=$this->replace_special_tag($qcode,$p_tag);
}
if (preg_match('/^CUSTATTR/', $p_tag) == 1)
@@ -1106,7 +1107,7 @@ class Document
if ( isset($p_array['qcode_dest']) || isset($p_array['e_client']) )
{
$qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
- $r=$this->replace_special_tag($id,$p_tag);
+ $r=$this->replace_special_tag($qcode,$p_tag);
}
}
return $r;
@@ -1142,7 +1143,7 @@ class Document
}
/**
*Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
- * is the ad_value
+ * is the ad_value
* @param $p_qcode qcode of the card
* @param $p_tag tag to parse
* @return the ad_value contained in fiche_detail or for the type "select" the
@@ -1151,35 +1152,35 @@ class Document
function replace_special_tag($p_qcode, $p_tag)
{
// check if the march exists
- if ($qcode == "")
+ if ($p_qcode == "")
return "";
$f = new Fiche($this->db);
- $found = $f->get_by_qcode($qcode, false);
+ $found = $f->get_by_qcode($p_qcode, false);
// if not found exit
if ($found == 1)
return "";
// get the ad_id
$attr=preg_replace("/^.*ATTR/","",$p_tag);
-
+
if (isNumber($attr) == 0) return "";
- $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1",$attr);
-
+ $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1",array($attr));
+
// get ad_value
$ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",array($f->id,$attr));
-
+
// if ad_id is type select execute select and get value
if ( $ad_type=="select")
{
- $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1",$attr);
+ $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1",array($attr));
$array= $this->db->make_array($sql);
for ($a=0;$aget_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;
- }
+
+ if ($p_mode == 'W')
+ {
+ $sel->value=$p_cn->make_array("
+ select r_id,r_name
+ from stock_repository join user_sec_repository using (r_id)
+ where
+ ur_right='W' and p_id=".sql_string($profile).
+ " order by 2" );
+ return $sel;
+ }
+ }
}
\ No newline at end of file
diff --git a/include/user_common.php b/include/user_common.php
index cc2f65f3e..4fc709191 100644
--- a/include/user_common.php
+++ b/include/user_common.php
@@ -52,18 +52,18 @@ require_once("class_acc_operation.php");
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 )
+ if ( $g_user->can_write_repo($p_depot) == false )
return false;
// Retrieve the good account for stock
$code = new Fiche($p_cn);
$code->get_by_qcode($p_good);
$code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
- if ( $code_marchandise == NOTFOUND )
+ if ( $code_marchandise == NOTFOUND )
return false;
-
+
$exercice = $g_user->get_exercice();
-
+
if ($exercice == 0)
throw new Exception('Annee invalide erreur');
@@ -72,12 +72,12 @@ function InsertStockGoods($p_cn, $p_j_id, $p_good, $p_quant, $p_type,$p_depot)
f_id,
sg_code,
sg_quantity,
- sg_type,sg_exercice,r_id ) values ($1,$2,$3,$4,$5,$6,$7)",
+ 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_quant,
$p_type,
$exercice,
$p_depot
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 8d681f36f..eff5593a3 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -262,6 +262,11 @@ COMMENT ON COLUMN user_sec_repository.ur_id IS 'pk';
COMMENT ON COLUMN user_sec_repository.p_id IS 'fk to profile';
COMMENT ON COLUMN user_sec_repository.r_id IS 'fk to stock_repository';
COMMENT ON COLUMN user_sec_repository.ur_right IS 'Type of right : R for readonly W for write';
+alter table stock_good add r_id bigint;
alter table user_sec_repository add constraint user_sec_repository_r_id_p_id_u unique (r_id,p_id);
-alter table user_sec_action_profile add constraint user_sec_action_profile_p_id_p_granted_u unique (p_id,p_granted);
\ No newline at end of file
+alter table user_sec_action_profile add constraint user_sec_action_profile_p_id_p_granted_u unique (p_id,p_granted);
+ALTER TABLE stock_goods ADD COLUMN r_id bigint;
+update stock_goods set r_id=1;
+ALTER TABLE stock_goods ADD CONSTRAINT stock_goods_sg_type CHECK (sg_type = 'c'::bpchar OR sg_type = 'd'::bpchar);
+CREATE INDEX fk_stock_good_repository_r_id ON stock_goods (r_id );
\ No newline at end of file