noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
stock.class.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 manage the stocks
26 *
27 *
28 */
29
30/**
31 * @class Stock
32 * @brief manage the stocks
33 */
34require_once NOALYSS_INCLUDE.'/database/stock_sql.class.php';
35
36class Stock extends Stock_Sql
37{
38
39 /**
40 * show history of all the stock movement
41 * @param $p_array usually contains $_GET
42 */
43 function history($p_array)
44 {
45
47 $p_url = HtmlInput::get_to_string(array("gDossier", "ac", "wcard", "wdate_start", "wdate_end", "wrepo",
48 "wamount_start", "wamount_end", "wcode_stock", "wdirection"));
49
50 $tb = new Sort_Table();
51 $tb->add("Date", $p_url, " order by real_date asc", "order by real_date desc", "da", "dd");
52 $tb->add("Code Stock", $p_url, " order by sg_code asc", "order by sg_code desc", "sa", "sd");
53 $tb->add("Dépôt", $p_url, " order by r_name asc", "order by r_name desc", "ra", "rd");
54 $tb->add("Fiche", $p_url, " order by 2 asc", "order by 2 desc", "fa", "fd");
55 $tb->add("Commentaire", $p_url, " order by coalesce(sg_comment,jr_comment) asc", "order by coalesce(sg_comment,jr_comment) desc", "ca", "cd");
56 $tb->add("Montant", $p_url, " order by j_montant asc", "order by j_montant desc", "ja", "jd");
57 $tb->add("Quantité", $p_url, " order by sg_quantity asc", "order by sg_quantity desc", "qa", "qd");
58 $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");
59 $order = (isset($p_array['ord'])) ? $p_array['ord'] : 'da';
60
61 $sql.=$tb->get_sql_order($order);
62 $step = $_SESSION[SESSION_KEY.'g_pagesize'];
63 $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
64 $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
65
66 $res = $this->cn->exec_sql($sql);
67
69
70 $nav_bar = navigation_bar($offset, $max_row, 0, $page);
71
72 if ($step != -1)
73 $res = $this->cn->exec_sql($sql . " , sg_id asc limit " . $step . " offset " . $offset);
75
76 $this->search_box_button();
77 $this->search_box($p_array);
78 require_once NOALYSS_TEMPLATE.'/stock_histo.php';
80 echo HtmlInput::print_window();
81 }
82
84 {
85 echo '<form style="display:inline" method="GET" action="export.php">';
86 echo HtmlInput::get_to_hidden(array("gDossier", "wcard", "wdate_start", "wdate_end", "wrepo",
87 "wamount_start", "wamount_end", "wcode_stock", "wdirection"));
88 echo HtmlInput::hidden('act','CSV:StockHisto');
89 echo HtmlInput::submit('stockhisto','Export CSV');
90 echo '</form>';
91 }
93 {
94 echo '<form style="display:inline" method="GET" action="export.php">';
95 echo HtmlInput::get_to_hidden(array("gDossier", "state_exercice"));
96 echo HtmlInput::hidden('act','CSV:StockResmList');
97
98 echo HtmlInput::submit('stockresm','Export CSV');
99 echo '</form>';
100 }
102 {
103 $bt = HtmlInput::button("Recherche", "Recherche", ' onclick="$(\'histo_search_d\').show();"');
104 echo $bt;
105 }
106
108 {
109 // Declaration
110 global $g_user;
111 $wrepo = HtmlInput::select_stock($this->cn, "wrepo", 'R');
112 $wrepo->value[] = array('value' => -1, 'label' => 'Tous les dépôts');
113
114 $wdate_start = new IDate('wdate_start');
115 $wdate_end = new IDate('wdate_end');
116 $wamount_start = new INum('wamount_start');
117 $wamount_end = new INum('wamount_end');
118 $wcard = new ICard('wcard');
119 $wcode_stock = new ICard('wcode_stock');
120 $wdirection = new ISelect("wdirection");
121
122 // value
123 $wrepo->selected = HtmlInput::default_value("wrepo", -1, $p_array);
124
125 // Date start / end
126 $exercice = $g_user->get_exercice();
127 $periode = new Periode($this->cn);
128 list($periode_start, $periode_end) = $periode->get_limit($exercice);
129
130 $wdate_start->value = HtmlInput::default_value("wdate_start", $periode_start->first_day(), $p_array);
131 $wdate_end->value = HtmlInput::default_value("wdate_end", $periode_end->last_day(), $p_array);
132 //amounts
133 $wamount_start->value = HtmlInput::default_value("wamount_start", 0, $p_array);
134 $wamount_end->value = HtmlInput::default_value("wamount_end", 0, $p_array);
135
136 //Card
137 $wcard->extra = "all";
138 $wcard->set_attribute("typecard", "all");
139 $wcard->value = HtmlInput::default_value("wcard", "", $p_array);
140
141 //Card stock
142 $wcode_stock->extra = " [sql] fd_id=500000 ";
143 $wcode_stock->set_attribute("typecard", "[sql] fd_id=500000");
144 $wcode_stock->value = HtmlInput::default_value("wcard", "", $p_array);
145
146 // Repository
147 $wcode_stock->value = HtmlInput::default_value("wcode_stock", "", $p_array);
148
149 //Direction
150 $wdirection->value = array(
151 array('value' => "-1", 'label' => "Tout"),
152 array('value' => "c", 'label' => "OUT"),
153 array('value' => "d", 'label' => "IN")
154 );
155 $wdirection->selected = HtmlInput::default_value("wdirection", "-1", $p_array);
156
157 require_once NOALYSS_TEMPLATE.'/stock_histo_search.php';
158 }
159
161 {
162 global $cn,$g_user;
163 $profile=$g_user->get_profile();
164 $sql = "
165 with tiers_id as (
166 select qp_supplier as f_tiers, j_id
167 from quant_purchase
168 union all
169 select qs_client , j_id
170 from quant_sold)
171 select sg_id,
172 sg.f_id,
173 (select ad_value from fiche_Detail as fd1 where ad_id=1 and fd1.f_id=jx.f_id) as fname,
174 (select ad_value from fiche_Detail as fd1 where ad_id=23 and fd1.f_id=jx.f_id) as qcode,
175 (select ad_value from fiche_Detail as fd3 where fd3.ad_id=1 and fd3.f_id=tier1.f_tiers) as fname_tiers,
176 (select ad_value from fiche_Detail as fd4 where fd4.ad_id=23 and fd4.f_id=tier1.f_tiers) as qcode_tiers,
177 sg_code,
178 coalesce(sg_comment,jr_comment) as ccomment,
179 sg_exercice,
180 r_name,
181 sg.r_id,
182 j_montant,
183 jr_date,
184 sg_quantity,
185 case when sg_type='c' then 'OUT' when sg_type='d' then 'IN' end as direction,
186 jr_internal,
187 jr_id,
188 coalesce(sg_date,jr_date) as real_date,
189 to_char(coalesce(sg_date,jr_date),'DD.MM.YY') as cdate,
190 tier1.f_tiers,
191 j.jr_pj_number
192 from stock_goods as sg
193 join stock_repository as sr on (sg.r_id=sr.r_id)
194 left join jrnx as jx on (sg.j_id=jx.j_id)
195 left join jrn as j on (j.jr_grpt_id=jx.j_grpt)
196 left join tiers_id as tier1 on (tier1.j_id=sg.j_id)
197 where
198 sg.r_id in (select r_id from profile_sec_repository where p_id = $profile)";
199 $and = " and ";
200 $clause = "";
201 if (isset($p_array['wdate_start']) && $p_array['wdate_start'] != '')
202 {
203 $clause = $and." to_date('" . sql_string($p_array['wdate_start']) . "','DD.MM.YYYY')<=coalesce(sg_date,jr_date) ";
204 }else{
205 $exercice=$g_user->get_exercice();
206 $periode=new Periode($cn);
207 $limit=$periode->get_limit($exercice);
208 $clause = $and.sprintf(" to_date ('%s','DD.MM.YYYY') <=coalesce(sg_date,jr_date)",$limit[0]->first_day());
209 }
210 if (isset($p_array['wdate_end']) && $p_array['wdate_end'] != '')
211 {
212 $clause.=$and . " to_date('" . sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) ";
213 }else {
214 $exercice=$g_user->get_exercice();
215 $periode=new Periode($cn);
216 $limit=$periode->get_limit($exercice);
217 $clause .= $and.sprintf(" to_date ('%s','DD.MM.YYYY') >= coalesce(sg_date,jr_date)",$limit[1]->last_day());
218 }
219 if (isset($p_array['wamount_start']) && $p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1
220 && $p_array['wamount_start'] != 0 )
221 {
222 $clause.=$and . " j_montant >= " . sql_string($p_array['wamount_start']);
223 }
224 if (isset($p_array['wamount_end'])
225 && $p_array['wamount_end'] != ''
226 && $p_array['wamount_end'] != 0
227 && isNumber($p_array['wamount_end']) == 1)
228 {
229 $clause.=$and . " j_montant <= " . sql_string($p_array['wamount_end']);
230 }
231 if (isset($p_array['wcard']) && $p_array['wcard'] != '')
232 {
233 $f = new Fiche($this->cn);
234 $f->get_by_qcode($p_array['wcard'], false);
235 if ($f->id != 0)
236 {
237 $clause.=$and . " sg.f_id = " . sql_string($f->id);
238 }
239 }
240 if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] != "")
241 {
242 $clause.=$and . " upper(sg_code) = upper('" . sql_string(trim($p_array['wcode_stock'])) . "')";
243 }
244 if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1)
245 {
246 $clause.=$and . " sg.r_id = " . sql_string($p_array['wrepo']);
247 }
248 if (isset($p_array['wdirection']) && $p_array['wdirection'] != -1)
249 {
250 $clause.=$and . " sg.sg_type = '" . sql_string($p_array['wdirection']) . "'";
251 }
252
253 return $sql . $clause;
254 }
255 /**
256 * @brief Display the status of the repository : nb of item IN / OUT and Difference
257 * @global $cn (Database) Db connexion
258 * @global $g_user (Noalyss_User) connected user
259 * @param $p_array (array)
260 * - [state_exercice] => 2025-12-31 date
261 - [present] => L type of presentation T table, L listing
262 */
264 {
265 global $cn, $g_user;
267 // Build condition
268 $a_repository = $g_user->get_available_repository('R');
269 $a_code = $cn->get_array("select distinct sg_code from tmp_stockgood_detail where s_id=$1", array($tmp_id));
270 if (isset($p_array['present']))
271 {
272 $present = $p_array['present'];
273 }
274 else
275 {
276 $present = 'T';
277 }
278 if ($present == 'T')
279 {
280 require_once NOALYSS_TEMPLATE.'/stock_summary_table.php';
281 }
282 if ($present == 'L')
283 {
284 require_once NOALYSS_TEMPLATE.'/stock_summary_list.php';
286
287 }
288 echo HtmlInput::print_window();
289 }
291 {
292 global $cn,$g_user;
293 // exercice
294 if (isset ($p_array['state_exercice']))
295 {
296 $periode=new Periode($cn);
297 $date= format_date($p_array['state_exercice'], 'YYYY-MM-DD');
298 $periode->find_periode($date);
299
300 } else {
301 $periode_id=$g_user->get_periode();
302 $periode=new Periode($cn,$periode_id);
303 }
304 $periode->load();
305 $tmp_id = $cn->get_next_seq("public.tmp_stockgood_s_id_seq");
306 $cn->exec_sql("delete from tmp_stockgood where s_date < now() - interval '2 days' ");
307 $cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)", array($tmp_id));
308
309 // get all readable repository
310 $a_repository = $g_user->get_available_repository('R');
311
312 // From ACH : IN
313 $sql_repo_detail = "
314 insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
315 select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qin,r_id,f_id
316 from stock_goods
317 where
318 sg_type='d'
319 and j_id is not null
320 and j_id in (select j_id from jrnx where j_tech_per in (select p_id from parm_periode where p_exercice=$2))
321 and r_id in (select r_id from profile_sec_repository where p_id=$1)
322 group by r_id,trim(sg_code),f_id
323 ";
324
325 // From VEN : out
326 $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
327 $sql_repo_detail = "
328 insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
329 select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qout,r_id,f_id
330 from stock_goods as sg
331 where
332 sg_type='c'
333 and sg.j_id is not null
334 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))
335 and sg.r_id in (select r_id from profile_sec_repository where p_id=$1)
336 group by r_id,trim(sg_code),f_id
337 ";
338 $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
339
340 // From INV IN
341 $sql_repo_detail = "
342 insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id)
343 select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qin,r_id,f_id
344 from stock_goods as sg
345 where
346 sg_type='d'
347 and j_id is null
348 and sg_date >= ( select min(p_start) from parm_periode where p_exercice=$2)
349 and sg_date <= ( select max(p_end) from parm_periode where p_exercice=$2)
350 and sg.r_id in (select r_id from profile_sec_repository where p_id=$1)
351 group by r_id,trim(sg_code),f_id
352 ";
353 // From INV: OUT
354 $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
355 $sql_repo_detail = "
356 insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id)
357 select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qout,r_id,f_id
358 from stock_goods
359 where
360 sg_type='c'
361 and j_id is null
362 and r_id in (select r_id from profile_sec_repository where p_id=$1)
363 and sg_date >= ( select min(p_start) from parm_periode where p_exercice=$2)
364 and sg_date <= ( select max(p_end) from parm_periode where p_exercice=$2)
365 group by r_id,trim(sg_code),f_id
366 ";
367 $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $periode->p_exercice));
368 return $tmp_id;
369 }
370
371
372}
373
374?>
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
isNumber($p_int)
sql_string($p_string)
Fix the problem with the quote char for the database.
global $g_user
if no group available , then stop
catch(Exception $e) $exercice
$periode_id
$input_from cn
$_GET['qcode']
static num_row($ret)
wrapper for the function pg_num_rows
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Description of class_syn_sort_table.
ORM abstract of the table public.stock_repository.
manage the stocks
create_query_histo($p_array)
history($p_array)
show history of all the stock movement
summary($p_array)
Display the status of the repository : nb of item IN / OUT and Difference @global $cn (Database) Db c...
export_stock_summary_list_form()
export_stock_histo_form()
build_tmp_table($p_array)
search_box_button()
search_box($p_array)
$periode_start
Definition fiche.inc.php:60
$periode_end
Definition fiche.inc.php:61
if($g_parameter->MY_STOCK=='N') if(isset( $_POST[ 'add_stock'])) if(isset($_POST['mod_stock'])) $tb
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)