diff --git a/html/ajax_misc.php b/html/ajax_misc.php index b1c0f6a71..a51412440 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -554,6 +554,9 @@ EOF; case 'mod_stock_repo': require_once 'ajax_mod_stock_repo.php'; break; + case 'view_mod_stock': + require_once 'ajax_view_mod_stock.php'; + break; default: var_dump($_GET); } diff --git a/html/js/scripts.js b/html/js/scripts.js index 72c6c0a13..911d0143e 100644 --- a/html/js/scripts.js +++ b/html/js/scripts.js @@ -1539,3 +1539,26 @@ function stock_repo_change(p_dossier,r_id) } ); } +function stock_inv_detail(p_dossier,p_id) +{ + var queryString="gDossier="+p_dossier+"&op=view_mod_stock"+"&c_id="+p_id+"&ctl=view_mod_stock_div"; + var nTop=calcy(posY); + var nLeft="200px"; + var str_style="top:"+nTop+"px;left:"+nLeft+";width:75%;"; + + removeDiv('view_mod_stock_div'); + waiting_box(); + var action = new Ajax.Request( + "ajax_misc.php" , + { + method:'get', parameters:queryString, + onFailure:ajax_misc_failure, + onSuccess:function(req){ + remove_waiting_box(); + add_div({id:'view_mod_stock_div',style:str_style,cssclass:'inner_box',drag:"1"}); + $('view_mod_stock_div').innerHTML=req.responseText; + req.responseText.evalScripts(); + } + } + ); +} \ No newline at end of file diff --git a/include/ajax_view_mod_stock.php b/include/ajax_view_mod_stock.php new file mode 100644 index 000000000..ca0a0ba23 --- /dev/null +++ b/include/ajax_view_mod_stock.php @@ -0,0 +1,45 @@ +get_array("select * from stock_goods where c_id=$1",array($_GET['c_id'])); +echo HtmlInput::title_box("Détail changement",$_GET['ctl']); +$p_array=array(); +$p_array['p_date']=$cn->get_value("select to_char(c_date,'DD.MM.YYYY') from stock_change where c_id=$1",array($_GET['c_id'])); +$p_array['p_motif']=$cn->get_value("select c_comment from stock_change where c_id=$1",array($_GET['c_id'])); +$p_array['p_depot']=$cn->get_value("select r_id from stock_change where c_id=$1",array($_GET['c_id'])); +for ($i=0;$iinput($p_array,true); +?> diff --git a/include/class_stock.php b/include/class_stock.php index 335dd373b..f9a160a50 100644 --- a/include/class_stock.php +++ b/include/class_stock.php @@ -31,40 +31,6 @@ require 'class_stock_sql.php'; class Stock extends Stock_Sql { - /* * * - * @brief return an array of f_id and f_name - * - * - * @param _sg_code stock_goods.sg_code - * @return - array (f_id, f_label) or null if nothing is found - */ - - function getCardNameCode($p_sg_code) - { - // Sql stmt - $sql = "select distinct f_id,ad_value - from stock_goods - join fiche_detail using(f_id) - where - ad_id=$1 - and sg_code=upper($2) - "; -// Execute - $Res = $this->cn->exec_sql($sql, array(ATTR_DEF_STOCK, $p_sg_code)); - if (( $M = Database::num_row($Res)) == 0) - return null; - -// Store in an array - for ($i = 0; $i < $M; $i++) - { - $r = Database::fetch_array($Res, $i); - $a['f_id'] = $r['f_id']; - $a['av_text'] = $this->cn->get_value("select ad_value from fiche_detail where ad_id=1 and f_id=$2", array($r['f_id'])); - $result[$i] = $a; - } - - return $result; - } function view_detail_stock($p_sg_code, $p_year) { @@ -343,6 +309,8 @@ class Stock extends Stock_Sql function create_query_histo($p_array) { + global $cn,$g_user; + $profile=$g_user->get_profile(); $sql = " select sg_id, sg.f_id, @@ -364,36 +332,29 @@ class Stock extends Stock_Sql from stock_goods as sg join stock_repository as sr on (sg.r_id=sr.r_id) left join jrnx as jx on (sg.j_id=jx.j_id) - left join jrn as j on (j.jr_grpt_id=jx.j_grpt)"; - $where = ""; - $and = ""; + left join jrn as j on (j.jr_grpt_id=jx.j_grpt) + where + sg.r_id in (select r_id from user_sec_repository where p_id = $profile)"; + $and = " and "; $clause = ""; if (isset($p_array['wdate_start']) && $p_array['wdate_start'] != '') { - $where = "where "; - $clause = " to_date('" . sql_string($p_array['wdate_start']) . "','DD.MM.YYYY')<=coalesce(sg_date,jr_date) "; - $and = " and "; + $clause = $and." to_date('" . sql_string($p_array['wdate_start']) . "','DD.MM.YYYY')<=coalesce(sg_date,jr_date) "; } if (isset($p_array['wdate_end']) && $p_array['wdate_end'] != '') { - $where = "where "; $clause.=$and . " to_date('" . sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) "; - $and = " and "; } if (isset($p_array['wamount_start']) && $p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1) { - $where = "where "; $clause.=$and . " j_montant >= " . sql_string($p_array['wamount_start']); - $and = " and "; } if (isset($p_array['wamount_end']) && $p_array['wamount_end'] != '' && $p_array['wamount_end'] != 0 && isNumber($p_array['wamount_end']) == 1) { - $where = "where "; $clause.=$and . " j_montant <= " . sql_string($p_array['wamount_end']); - $and = " and "; } if (isset($p_array['wcard']) && $p_array['wcard'] != '') { @@ -401,30 +362,22 @@ class Stock extends Stock_Sql $f->get_by_qcode($p_array['wcard'], false); if ($f->id != 0) { - $where = "where "; $clause.=$and . " sg.f_id = " . sql_string($f->id); - $and = " and "; } } if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] != "") { - $where = "where "; $clause.=$and . " upper(sg_code) = upper('" . sql_string($p_array['wcode_stock']) . "')"; - $and = " and "; } if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1) { - $where = "where "; $clause.=$and . " sg.r_id = " . sql_string($p_array['wrepo']); - $and = " and "; } if (isset($p_array['wdirection']) && $p_array['wdirection'] != -1) { - $where = "where "; $clause.=$and . " sg.sg_type = '" . sql_string($p_array['wdirection']) . "'"; - $and = " and "; } - return $sql . $where . $clause; + return $sql . $clause; } function summary($p_array) @@ -493,7 +446,7 @@ class Stock extends Stock_Sql 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 + (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) "; diff --git a/include/class_stock_goods.php b/include/class_stock_goods.php new file mode 100644 index 000000000..70baa0374 --- /dev/null +++ b/include/class_stock_goods.php @@ -0,0 +1,127 @@ +setReadOnly($p_readonly); + $motif = new IText('p_motif', $p_motif); + $motif->setReadOnly($p_readonly); + $motif->size = 80; + $idepo = HtmlInput::select_stock($cn, "p_depot", "W"); + $idepo->setReadOnly($p_readonly); + if (count($idepo->value) == 0) + { + NoAccess(); + exit(); + } + $idepo->selected = $p_depot; + for ($e = 0; $e < MAX_ARTICLE; $e++) + { + $sg_code[$e] = new ICard('sg_code' . $e); + $sg_code[$e]->extra = '[sql] fd_id = 500000'; + $sg_code[$e]->set_attribute("typecard", $sg_code[$e]->extra); + $sg_code[$e]->set_attribute("label", "label" . $e); + $sg_code[$e]->value = (isset(${'sg_code' . $e})) ? ${'sg_code' . $e} : ''; + $sg_quantity[$e] = new INum('sg_quantity' . $e); + $sg_quantity[$e]->value = (isset(${'sg_quantity' . $e})) ? ${'sg_quantity' . $e} : ''; + $label[$e] = new ISpan("label$e"); + if (trim($sg_code[$e]->value) != '') + { + $label[$e]->value = $cn->get_value("select vw_name from vw_fiche_attr where quick_code=$1", array($sg_code[$e]->value)); + } + $sg_code[$e]->setReadOnly($p_readonly); + $sg_quantity[$e]->setReadOnly($p_readonly); + } + require_once 'template/stock_inv.php'; + } + + function save($p_array) + { + global $cn; + try + { + if (isDate($p_array['p_date']) == null) + throw new Exception('Date invalide'); + $cn->start(); + $ch = new Stock_Change_Sql(); + $ch->setp("c_comment", $p_array['p_motif']); + $ch->setp("r_id", $p_array['p_depot']); + $ch->setp("c_date", $p_array['p_date']); + $ch->setp('tech_user', $_SESSION['g_user']); + $ch->insert(); + $per = new Periode($cn); + $periode = $per->find_periode($p_array['p_date']); + $exercice = $per->get_exercice($periode); + + for ($i = 0; $i < MAX_ARTICLE; $i++) + { + $a = new Stock_Goods_Sql(); + if ($p_array['sg_quantity' . $i] != 0 && + trim($p_array['sg_code' . $i]) != '') + { + $a->sg_code = $p_array['sg_code' . $i]; + $a->sg_quantity = $p_array['sg_quantity' . $i]; + $a->sg_type = ($p_array['sg_quantity' . $i] > 0) ? 'd' : 'c'; + $a->sg_comment = $p_array['p_motif']; + $a->tech_user = $_SESSION['g_user']; + $a->r_id = $p_array['p_depot']; + $a->sg_exercice = $exercice; + $a->c_id = $ch->c_id; + $a->insert(); + } + } + $cn->commit(); + } + catch (Exception $exc) + { + echo $exc->getTraceAsString(); + throw $exc; + } + } + +} + +?> diff --git a/include/class_stock_goods_sql.php b/include/class_stock_goods_sql.php new file mode 100644 index 000000000..0beaae5a5 --- /dev/null +++ b/include/class_stock_goods_sql.php @@ -0,0 +1,121 @@ +table = "public.stock_goods"; + $this->primary_key = "sg_id"; + $this->date_format="DD.MM.YYYY"; + + $this->name = array( + "sg_id" => "sg_id", + "j_id" => "j_id", + "f_id" => "f_id", + "sg_code" => "sg_code", + "sg_quantity" => "sg_quantity", + "sg_type" => "sg_type", + "sg_date" => "sg_date", + "sg_tech_date" => "sg_tech_date", + "sg_tech_user" => "sg_tech_user", + "sg_comment" => "sg_comment", + "sg_exercice" => "sg_exercice", + "r_id" => "r_id", + "c_id"=>"c_id" + ); + + $this->type = array( + "sg_id" => "numeric", + "j_id" => "numeric", + "f_id" => "numeric", + "sg_code" => "text", + "sg_quantity" => "text", + "sg_type" => "text", + "sg_date" => "date", + "sg_tech_date" => "date", + "sg_tech_user" => "text", + "sg_comment" => "text", + "sg_exercice" => "sg_exercice", + "r_id" => "numeric", + "c_id" => "numeric" + + ); + + $this->default = array( + "sg_id" => "auto", + "sg_tech_date" => "auto", + "sg_user" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } + +} + +class Stock_Change_Sql extends PhpCompta_Sql +{ + + function __construct($p_id = -1) + { + $this->date_format="DD.MM.YYYY"; + $this->table = "public.stock_change"; + $this->primary_key = "c_id"; + + $this->name = array( + "id" => "c_id", + "c_comment" => "c_comment", + "c_date" => "c_date", + "tech_date"=>"tech_date", + "tech_user"=>"tech_user", + "r_id"=>"r_id" + ); + + $this->type = array( + "c_id" => "numeric", + "c_comment" => "text", + "c_date" => "date", + "tech_date"=>"date", + "tech_user"=>"text", + "r_id"=>"numeric" + ); + + $this->default = array( + "c_id" => "auto", + "tech_date" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } +} +?> diff --git a/include/stock_inv.inc.php b/include/stock_inv.inc.php new file mode 100644 index 000000000..023ebf00f --- /dev/null +++ b/include/stock_inv.inc.php @@ -0,0 +1,49 @@ +save($_POST); + echo h2info("Opération sauvée"); + $inv->input($_POST,true); + + }catch(Exception $e) + { + alert($e->getMessage()); + $inv->input($_POST); + } +} +echo $inv->input(); + +?> diff --git a/include/stock_inv_histo.inc.php b/include/stock_inv_histo.inc.php new file mode 100644 index 000000000..74410763f --- /dev/null +++ b/include/stock_inv_histo.inc.php @@ -0,0 +1,78 @@ +get_profile(); +$a_change=$cn->get_array("select *,to_char(c_date,'DD.MM.YY') as str_date from stock_change as sc + join stock_repository as sr on (sc.r_id=sr.r_id) + where sc.r_id in (select r_id from user_sec_repository where p_id=$profile) + order by c_date"); +$gDossier=dossier::id(); +?> +
+ + + + + + + + + + + + > + + + + + + + + + +
+ Date + + Commentaire + + Dépot + + Utilisateur + + +
+ + + + + + + + + +
+
diff --git a/include/template/stock_inv.php b/include/template/stock_inv.php new file mode 100644 index 000000000..56ab307ec --- /dev/null +++ b/include/template/stock_inv.php @@ -0,0 +1,85 @@ + +
+
+ + + + + + + + + + + + +
+ Date + + input()?> +
+ Dépot + + input()?> +
+ Motif de changement + + input()?> +
+ + + + + + + + + + + +
+ Code Stock + + Quantité +
+ input()?> + search()?> + input()?> + + value==0 && $p_readonly==true):?> + + + input()?> + +
+ +
+
\ No newline at end of file diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 1f4ff88cc..384abd8b8 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -278,6 +278,7 @@ update menu_ref set me_file=null where me_code='STOCK'; insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_HISTO','stock_histo.inc.php','Historique stock','Historique des mouvement de stock','ME'); insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_STATE','stock_state.inc.php','Etat des stock','Etat des stock','ME'); +insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_INVHISTO','stock_inv_histo.inc.php','Histo. Changement','Liste des changements manuels des stocks','ME'); insert into menu_ref (me_code,me_menu,me_type) values ('CSV:StockHisto','Export Historique mouvement stock','PR'); insert into menu_ref (me_code,me_menu,me_type) values ('CSV:StockResmList','Export Résumé list stock','PR'); @@ -285,10 +286,16 @@ insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_STATE','STOCK',1,20,'E'); insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_HISTO','STOCK',2,10,'E'); insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_STATE','STOCK',2,20,'E'); +insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INVHISTO','STOCK',1,30,'E'); +insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INVHISTO','STOCK',2,30,'E'); insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockHisto',1,'P'); insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockResmList',1,'P'); insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockHisto',2,'P'); insert into profile_menu(me_code,p_id,p_type_display) values ('CSV:StockResmList',2,'P'); +insert into menu_ref (me_code,me_file,me_menu,me_description,me_type) values ('STOCK_INV','stock_inv.inc.php','Modification Stocks','Modification des stocks (inventaire)','ME'); +insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INV','STOCK',1,30,'E'); +insert into profile_menu(me_code,me_code_dep,p_id,p_order,p_type_display) values ('STOCK_INV','STOCK',2,30,'E'); + -- clean stock_goods delete from stock_goods where sg_code is null or sg_code='' or sg_code not in (select ad_value from fiche_detail as fd where ad_id=19 and ad_value is not null); @@ -361,4 +368,17 @@ $BODY$ LANGUAGE plpgsql VOLATILE; -CREATE TRIGGER fiche_detail_upd_trg BEFORE UPDATE ON fiche_detail FOR EACH ROW EXECUTE PROCEDURE comptaproc.fiche_detail_qcode_upd(); \ No newline at end of file +CREATE TRIGGER fiche_detail_upd_trg BEFORE UPDATE ON fiche_detail FOR EACH ROW EXECUTE PROCEDURE comptaproc.fiche_detail_qcode_upd(); + +update menu_ref set me_description='Gestion des attributs de fiches ' where me_code='CFGATCARD'; + +ALTER TABLE stock_goods ADD CONSTRAINT stock_goods_c_id_fkey FOREIGN KEY (c_id) REFERENCES stock_change (c_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE; + +CREATE TABLE stock_change +( + c_id bigserial NOT NULL, + c_comment text, + c_date date, + CONSTRAINT stock_change_pkey PRIMARY KEY (c_id ) +); \ No newline at end of file