noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_stock.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 // Copyright Author Dany De Bontridder danydb@aevalys.eu
22 
23 /**
24  * @file
25  * @brief
26  *
27  *
28  */
29 require_once NOALYSS_INCLUDE.'/database/class_stock_sql.php';
30 
31 class Stock extends Stock_Sql
32 {
33 
34  /**
35  * show history of all the stock movement
36  * @param $p_array usually contains $_GET
37  */
38  function history($p_array)
39  {
40 
42  require_once NOALYSS_INCLUDE.'/lib/class_sort_table.php';
43  $p_url = HtmlInput::get_to_string(array("gDossier", "ac", "wcard", "wdate_start", "wdate_end", "wrepo",
44  "wamount_start", "wamount_end", "wcode_stock", "wdirection"));
45 
46  $tb = new Sort_Table();
47  $tb->add("Date", $p_url, " order by real_date asc", "order by real_date desc", "da", "dd");
48  $tb->add("Code Stock", $p_url, " order by sg_code asc", "order by sg_code desc", "sa", "sd");
49  $tb->add("Dépôt", $p_url, " order by r_name asc", "order by r_name desc", "ra", "rd");
50  $tb->add("Fiche", $p_url, " order by 2 asc", "order by 2 desc", "fa", "fd");
51  $tb->add("Commentaire", $p_url, " order by coalesce(sg_comment,jr_comment) asc", "order by coalesce(sg_comment,jr_comment) desc", "ca", "cd");
52  $tb->add("Montant", $p_url, " order by j_montant asc", "order by j_montant desc", "ja", "jd");
53  $tb->add("Quantité", $p_url, " order by sg_quantity asc", "order by sg_quantity desc", "qa", "qd");
54  $tb->add("IN/OUT", $p_url, " order by (case when sg_type='c' then 'OUT' when sg_type='c' then 'IN' end ) asc", "order by (case when sg_type='c' then 'OUT' when sg_type='c' then 'IN' end ) desc", "ta", "td");
55  $order = (isset($p_array['ord'])) ? $p_array['ord'] : 'da';
56 
57  $sql.=$tb->get_sql_order($order);
58  $step = $_SESSION['g_pagesize'];
59  $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
60  $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
61 
62  $res = $this->cn->exec_sql($sql);
63 
65 
66  $nav_bar = navigation_bar($offset, $max_row, 0, $page);
67 
68  if ($step != -1)
69  $res = $this->cn->exec_sql($sql . " , sg_id asc limit " . $step . " offset " . $offset);
71 
72  $this->search_box_button();
73  $this->search_box($p_array);
74  require_once NOALYSS_TEMPLATE.'/stock_histo.php';
75  $this->export_stock_histo_form();
77  }
78 
80  {
81  echo '<form style="display:inline" method="GET" action="export.php">';
82  echo HtmlInput::get_to_hidden(array("gDossier", "wcard", "wdate_start", "wdate_end", "wrepo",
83  "wamount_start", "wamount_end", "wcode_stock", "wdirection"));
84  echo HtmlInput::hidden('act','CSV:StockHisto');
85  echo HtmlInput::submit('stockhisto','Export CSV');
86  echo '</form>';
87  }
89  {
90  echo '<form style="display:inline" method="GET" action="export.php">';
91  echo HtmlInput::get_to_hidden(array("gDossier", "state_exercice"));
92  echo HtmlInput::hidden('act','CSV:StockResmList');
93 
94  echo HtmlInput::submit('stockresm','Export CSV');
95  echo '</form>';
96  }
97  function search_box_button()
98  {
99  $bt = HtmlInput::button("Recherche", "Recherche", ' onclick="$(\'histo_search_d\').show();"');
100  echo $bt;
101  }
102 
104  {
105  // Declaration
106  global $g_user;
107  $wrepo = HtmlInput::select_stock($this->cn, "wrepo", 'R');
108  $wrepo->value[] = array('value' => -1, 'label' => 'Tous les dépôts');
109 
110  $wdate_start = new IDate('wdate_start');
111  $wdate_end = new IDate('wdate_end');
112  $wamount_start = new INum('wamount_start');
113  $wamount_end = new INum('wamount_end');
114  $wcard = new ICard('wcard');
115  $wcode_stock = new ICard('wcode_stock');
116  $wdirection = new ISelect("wdirection");
117 
118  // value
119  $wrepo->selected = HtmlInput::default_value("wrepo", -1, $p_array);
120 
121  // Date start / end
122  $exercice = $g_user->get_exercice();
123  $periode = new Periode($this->cn);
124  list($periode_start, $periode_end) = $periode->get_limit($exercice);
125 
126  $wdate_start->value = HtmlInput::default_value("wdate_start", $periode_start->first_day(), $p_array);
127  $wdate_end->value = HtmlInput::default_value("wdate_end", $periode_end->last_day(), $p_array);
128  //amounts
129  $wamount_start->value = HtmlInput::default_value("wamount_start", 0, $p_array);
130  $wamount_end->value = HtmlInput::default_value("wamount_end", 0, $p_array);
131 
132  //Card
133  $wcard->extra = "all";
134  $wcard->set_attribute("typecard", "all");
135  $wcard->value = HtmlInput::default_value("wcard", "", $p_array);
136 
137  //Card stock
138  $wcode_stock->extra = " [sql] fd_id=500000 ";
139  $wcode_stock->set_attribute("typecard", "[sql] fd_id=500000");
140  $wcode_stock->value = HtmlInput::default_value("wcard", "", $p_array);
141 
142  // Repository
143  $wcode_stock->value = HtmlInput::default_value("wcode_stock", "", $p_array);
144 
145  //Direction
146  $wdirection->value = array(
147  array('value' => "-1", 'label' => "Tout"),
148  array('value' => "c", 'label' => "OUT"),
149  array('value' => "d", 'label' => "IN")
150  );
151  $wdirection->selected = HtmlInput::default_value("wdirection", "-1", $p_array);
152 
153  require_once NOALYSS_TEMPLATE.'/stock_histo_search.php';
154  }
155 
157  {
158  global $cn,$g_user;
159  $profile=$g_user->get_profile();
160  $sql = "
161  select sg_id,
162  sg.f_id,
163  (select ad_value from fiche_Detail as fd1 where ad_id=1 and fd1.f_id=jx.f_id) as fname,
164  (select ad_value from fiche_Detail as fd1 where ad_id=23 and fd1.f_id=jx.f_id) as qcode,
165  sg_code,
166  coalesce(sg_comment,jr_comment) as ccomment,
167  sg_exercice,
168  r_name,
169  sg.r_id,
170  j_montant,
171  jr_date,
172  sg_quantity,
173  case when sg_type='c' then 'OUT' when sg_type='d' then 'IN' end as direction,
174  jr_internal,
175  jr_id,
176  coalesce(sg_date,jr_date) as real_date,
177  to_char(coalesce(sg_date,jr_date),'DD.MM.YY') as cdate
178  from stock_goods as sg
179  join stock_repository as sr on (sg.r_id=sr.r_id)
180  left join jrnx as jx on (sg.j_id=jx.j_id)
181  left join jrn as j on (j.jr_grpt_id=jx.j_grpt)
182  where
183  sg.r_id in (select r_id from profile_sec_repository where p_id = $profile)";
184  $and = " and ";
185  $clause = "";
186  if (isset($p_array['wdate_start']) && $p_array['wdate_start'] != '')
187  {
188  $clause = $and." to_date('" . sql_string($p_array['wdate_start']) . "','DD.MM.YYYY')<=coalesce(sg_date,jr_date) ";
189  }
190  if (isset($p_array['wdate_end']) && $p_array['wdate_end'] != '')
191  {
192  $clause.=$and . " to_date('" . sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) ";
193  }
194  if (isset($p_array['wamount_start']) && $p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1
195  && $p_array['wamount_start'] != 0 )
196  {
197  $clause.=$and . " j_montant >= " . sql_string($p_array['wamount_start']);
198  }
199  if (isset($p_array['wamount_end'])
200  && $p_array['wamount_end'] != ''
201  && $p_array['wamount_end'] != 0
202  && isNumber($p_array['wamount_end']) == 1)
203  {
204  $clause.=$and . " j_montant <= " . sql_string($p_array['wamount_end']);
205  }
206  if (isset($p_array['wcard']) && $p_array['wcard'] != '')
207  {
208  $f = new Fiche($this->cn);
209  $f->get_by_qcode($p_array['wcard'], false);
210  if ($f->id != 0)
211  {
212  $clause.=$and . " sg.f_id = " . sql_string($f->id);
213  }
214  }
215  if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] != "")
216  {
217  $clause.=$and . " upper(sg_code) = upper('" . sql_string(trim($p_array['wcode_stock'])) . "')";
218  }
219  if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1)
220  {
221  $clause.=$and . " sg.r_id = " . sql_string($p_array['wrepo']);
222  }
223  if (isset($p_array['wdirection']) && $p_array['wdirection'] != -1)
224  {
225  $clause.=$and . " sg.sg_type = '" . sql_string($p_array['wdirection']) . "'";
226  }
227 
228  return $sql . $clause;
229  }
230 
231  function summary($p_array)
232  {
233  global $cn, $g_user;
235  // Build condition
236  $a_repository = $g_user->get_available_repository('R');
237  $a_code = $cn->get_array("select distinct sg_code from tmp_stockgood_detail where s_id=$1", array($tmp_id));
238  if (isset($p_array['present']))
239  {
240  $present = $p_array['present'];
241  }
242  else
243  {
244  $present = 'T';
245  }
246  if ($present == 'T')
247  {
248  require_once NOALYSS_TEMPLATE.'/stock_summary_table.php';
249  }
250  if ($present == 'L')
251  {
252  require_once NOALYSS_TEMPLATE.'/stock_summary_list.php';
254 
255  }
257  }
259  {
260  global $cn,$g_user;
261  // exercice
262  if (isset ($p_array['state_exercice']))
263  {
264  $periode=new Periode($cn);
265  $date= format_date($p_array['state_exercice'], 'YYYY-MM-DD');
266  $periode->find_periode($date);
267 
268  } else {
269  $periode_id=$g_user->get_periode();
270  $periode=new Periode($cn,$periode_id);
271  }
272  $periode->load();
273  $tmp_id = $cn->get_next_seq("public.tmp_stockgood_s_id_seq");
274  $cn->exec_sql("delete from tmp_stockgood where s_date < now() - interval '2 days' ");
275  $cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)", array($tmp_id));
276 
277  // get all readable repository
278  $a_repository = $g_user->get_available_repository('R');
279 
280  // From ACH : IN
281  $sql_repo_detail = "
282  insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
283  select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qin,r_id,f_id
284  from stock_goods
285  where
286  sg_type='d'
287  and j_id is not null
288  and j_id in (select j_id from jrnx where j_tech_per in (select p_id from parm_periode where p_exercice=$2))
289  and r_id in (select r_id from profile_sec_repository where p_id=$1)
290  group by r_id,trim(sg_code),f_id
291  ";
292 
293  // From VEN : out
294  $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
295  $sql_repo_detail = "
296  insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
297  select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qout,r_id,f_id
298  from stock_goods as sg
299  where
300  sg_type='c'
301  and sg.j_id is not null
302  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))
303  and sg.r_id in (select r_id from profile_sec_repository where p_id=$1)
304  group by r_id,trim(sg_code),f_id
305  ";
306  $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
307 
308  // From INV IN
309  $sql_repo_detail = "
310  insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
311  select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qin,r_id,f_id
312  from stock_goods as sg
313  where
314  sg_type='d'
315  and j_id is null
316  and sg_date >= ( select min(p_start) from parm_periode where p_exercice=$2)
317  and sg_date <= ( select max(p_end) from parm_periode where p_exercice=$2)
318  and sg.r_id in (select r_id from profile_sec_repository where p_id=$1)
319  group by r_id,trim(sg_code),f_id
320  ";
321  // From INV: OUT
322  $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
323  $sql_repo_detail = "
324  insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
325  select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qout,r_id,f_id
326  from stock_goods
327  where
328  sg_type='c'
329  and j_id is null
330  and r_id in (select r_id from profile_sec_repository where p_id=$1)
331  and sg_date >= ( select min(p_start) from parm_periode where p_exercice=$2)
332  and sg_date <= ( select max(p_end) from parm_periode where p_exercice=$2)
333  group by r_id,trim(sg_code),f_id
334  ";
335  $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
336  return $tmp_id;
337  }
338 
339 
340 }
341 
342 ?>
$_GET['qcode']
summary($p_array)
create_query_histo($p_array)
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
static num_row($ret)
wrapper for the function pg_NumRows
search_box($p_array)
export_stock_summary_list_form()
Definition: class_stock.php:88
$p_url
format_date($p_date, $p_from_format= 'YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
Definition: ac_common.php:767
isNumber(&$p_int)
Definition: ac_common.php:202
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
switch($ss_action) $f
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:81
static print_window()
Javascript to print the current window.
For the periode tables parm_periode and jrn_periode.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
static select_stock($p_cn, $p_name, $p_mode)
Create an ISelect object containing the available repository for reading or writing.
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
$input_from cn
Definition: balance.inc.php:71
static get_to_string($array, $start="?")
transform $_GET data to string
Description of class_syn_sort_table.
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
$periode_end
Definition: fiche.inc.php:52
$periode_start
Definition: fiche.inc.php:51
build_tmp_table($p_array)
static default_value($ind, $default, $array)
return default if the value if the value doesn't exist in the array
export_stock_histo_form()
Definition: class_stock.php:79
history($p_array)
show history of all the stock movement
Definition: class_stock.php:38
search_box_button()
Definition: class_stock.php:97
if($g_parameter->MY_STOCK== 'N') if(isset($_POST['add_stock'])) if(isset($_POST['mod_stock'])) $tb
static hidden($p_name, $p_value, $p_id="")
static get_to_hidden($array)
transform $_GET data to hidden
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: class_idate.php:31
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40