noalyss Version-9
stock_goods.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 goods
26 *
27 */
28
29/**
30 * @class Stock_Goods
31 * @brief Manage the goods
32 *
33 */
34require_once NOALYSS_INCLUDE.'/database/stock_goods_sql.class.php';
35
37{
38/**
39 * if an array if receive the keys are
40 * p_date
41 * p_depot
42 * f_idX f_id
43 * sg_codeX
44 * sg_type0
45 *
46 * @remark $cn database connx
47 * @param $p_array
48 * if an array if receive the keys are
49 * p_date
50 * p_depot
51 * f_idX f_id
52 * sg_codeX
53 * sg_type0
54 * @param $p_readonly true or false
55 */
56 function input($p_array = null, $p_readonly = false)
57 {
58 global $cn;
59
60 if ($p_array != null)
61 {
62 extract($p_array, EXTR_SKIP);
63 }
64 else
65 {
66 $p_date = '';
67 $p_motif = '';
68 $p_depot = 0;
69 }
70 $date = new IDate('p_date', $p_date);
71 $date->setReadOnly($p_readonly);
72 $motif = new IText('p_motif', $p_motif);
73 $motif->setReadOnly($p_readonly);
74 $motif->size = 80;
75 $idepo = HtmlInput::select_stock($cn, "p_depot", "W");
76 $idepo->setReadOnly($p_readonly);
77 if (empty($idepo->value) )
78 {
79 echo_warning(_("Aucun stock disponible"));
80 return;
81 }
82 $idepo->selected = $p_depot;
83 if ($p_readonly ) {
84 $nb=$row;
85 } else {
86 if (isset ($row ) )
87 {
89 }else {
91 }
92 }
93 for ($e = 0; $e < $nb; $e++)
94 {//ATTR_DEF_STOCKfiche_
95 $sg_code[$e] = new ICard('sg_code' . $e);
96 $sg_code[$e]->extra = "[sql] fd_id = 500000";
97 $sg_code[$e]->set_attribute("typecard", $sg_code[$e]->extra);
98 $sg_code[$e]->set_attribute("label", "label" . $e);
99 $sg_code[$e]->value = (isset(${'sg_code' . $e})) ? ${'sg_code' . $e} : '';
100 $sg_quantity[$e] = new INum('sg_quantity' . $e);
101 $sg_quantity[$e]->value = (isset(${'sg_quantity' . $e})) ? ${'sg_quantity' . $e} : '';
102 $label[$e] = new ISpan("label$e");
103 $label[$e]->style="vertical-align:top;";
104 if (trim($sg_code[$e]->value) != '')
105 {
106 $label[$e]->value = $cn->get_value("select vw_name from vw_fiche_attr where quick_code=$1", array($sg_code[$e]->value));
107 }
108 $sg_code[$e]->setReadOnly($p_readonly);
109 $sg_quantity[$e]->setReadOnly($p_readonly);
110 if ( isset (${'sg_type'.$e})) {
111 $sg_type[$e]=(${'sg_type'.$e}=='c')?'OUT':'IN';
112 }
113 if ( isset (${'f_id'.$e})) {
114 $fiche[$e]=new Fiche($this->cn,${'f_id'.$e});
115 }
116 }
117 $select_exercice=new ISelect('p_exercice');
118 $select_exercice->value=$cn->make_array('select distinct p_exercice,p_exercice from parm_periode order by 1 desc');
119
120 require_once NOALYSS_TEMPLATE.'/stock_inv.php';
121 }
122
124 {
125 global $cn;
126 try
127 {
128 if (isDate($p_array['p_date']) == null)
129 throw new Exception('Date invalide');
130 $cn->start();
131 $ch = new Stock_Change_Sql($cn);
132 $ch->setp("c_comment", $p_array['p_motif']);
133 $ch->setp("r_id", $p_array['p_depot']);
134 $ch->setp("c_date", $p_array['p_date']);
135 $ch->setp('tech_user', $_SESSION[SESSION_KEY.'g_user']);
136 $ch->insert();
137 $per = new Periode($cn);
138 $periode = $per->find_periode($p_array['p_date']);
139 $exercice = $per->get_exercice($periode);
140 $nb=$p_array['row'];
141 for ($i = 0; $i < $nb; $i++)
142 {
143 $a = new Stock_Goods_Sql($cn);
144 if ($p_array['sg_quantity' . $i] != 0 &&
145 trim($p_array['sg_code' . $i]) != '')
146 {
147 $stock= strtoupper(trim($p_array['sg_code' . $i]));
148 $fiche=new Fiche($cn);
149 $fiche->get_by_qcode($p_array['sg_code' . $i]);
150 /*
151 * check if code stock does exist
152 */
153 $count=$cn->get_value('select count(*) from fiche_detail where ad_id=$1 and ad_value=$2',
154 array(ATTR_DEF_STOCK,$stock));
155 if ( $count==0) {
156 throw new Exception(_("Code stock inutilisé").h($stock));
157 }
158 $a->f_id=$fiche->id;
159 $a->sg_code = $stock;
160 $a->sg_quantity = abs($p_array['sg_quantity' . $i]);
161 $a->sg_type = ($p_array['sg_quantity' . $i] > 0) ? 'd' : 'c';
162 $a->sg_comment = $p_array['p_motif'];
163 $a->tech_user = $_SESSION[SESSION_KEY.'g_user'];
164 $a->r_id = $p_array['p_depot'];
165 $a->sg_exercice = $exercice;
166 $a->c_id = $ch->c_id;
167 $a->sg_date=$p_array['p_date'];
168 $a->insert();
169 }
170 }
171 $cn->commit();
172 }
173 catch (Exception $exc)
174 {
175 record_log( $exc->getTraceAsString());
176 echo $exc->getMessage();
177 throw $exc;
178 }
179 }
180 /**
181 * Insert into stock_goods from ACH and VEN
182 * @param type $p_array KEY : db => database conx, j_id => jrnx.j_id,goods=> f_id of the goods
183 * 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for purchase IN),'repo'=>r_id of the
184 * repository (stock_repository.r_id
185 */
186 static function insert_goods(&$p_cn,$p_array)
187 {
188 global $g_user;
189 extract ($p_array, EXTR_SKIP);
190 if ($g_user->can_write_repo($repo) == false)
191 return false;
192
193 // Retrieve the good account for stock
194 $code = new Fiche($p_cn);
195 $code->get_by_qcode($goods);
196 $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
197 if ($code_marchandise == NOTFOUND || $code_marchandise=='')
198 return false;
199
200 $exercice = $g_user->get_exercice();
201
202 if ($exercice == 0)
203 throw new Exception('Annee invalide erreur');
204
205 $Res = $p_cn->exec_sql("insert into stock_goods (
206 j_id,
207 f_id,
208 sg_code,
209 sg_quantity,
210 sg_type,sg_exercice,r_id ) values ($1,$2,$3,$4,$5,$6,$7)", array(
211 $p_array['j_id'],
212 $code->id,
213 $code_marchandise,
214 $p_array['quant'],
215 $p_array['dir'],
216 $exercice,
217 $p_array['repo']
218 )
219 );
220 return $Res;
221 }
222 /**
223 * Return an array, used by Stock_Goods::input
224 * @remark type $cn
225 * @param type $p_array
226 * @throws Exception
227 */
229 {
230 global $cn;
231 $year=HtmlInput::default_value("p_exercice", "", $p_array);
232 $depot=HtmlInput::default_value("p_depot", "", $p_array);
233 if ($year=="")
234 throw new Exception(_('Inventaire invalide'), 10);
235 if ($depot=="")
236 throw new Exception(_('Dépôt invalide'), 20);
237
238 // compute state_exercice
239 $periode=new Periode($cn);
240 $periode->p_id=$cn->get_value("select min(p_id) from parm_periode where p_exercice=$1", array($year));
241 $first_day=$periode->first_day();
242
243 // compute array for stock
244 $array['state_exercice']=$first_day;
245
246 $stock=new Stock($cn);
247 $rowid=$stock->build_tmp_table($array);
248
249 // compute first day of the next year
250 $next_year=$year+1;
251 $periode=new Periode($cn);
252 $periode->p_id=$cn->get_value("select min(p_id) from parm_periode where p_exercice=$1", array($next_year));
253
254 if ($periode->p_id=="")
255 $array['p_date']="";
256 else
257 $array['p_date']=$periode->first_day();
258
259 // Compute an array compatible with Stock_Goods::input
260 $array['p_motif']=_('Inventaire ').$year;
261 $array['p_depot']=$depot;
262
263 $result=$cn->get_array("
264 select sg_code,sum(coalesce(s_qin,0)-coalesce(s_qout,0)) tot_
265 from tmp_stockgood_detail
266 where
267 s_id=$1 and r_id=$2
268 group by sg_code",
269 array($rowid,$depot));
270 for ($e=0;$e< count($result);$e++) {
271 $array['sg_code'.$e]=$result[$e]['sg_code'];
272 $array['sg_quantity'.$e]=$result[$e]['tot_'];
273 }
274 $array['row']=$e;
275 return $array;
276
277 }
278}
279
280?>
isDate($p_date)
Definition: ac_common.php:236
echo_warning($p_string)
warns
Definition: ac_common.php:589
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
global $g_user
if no group available , then stop
h( $row[ 'oa_description'])
$code
catch(Exception $e) $exercice
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
$input_from cn
Definition: balance.inc.php:66
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
static select_stock($p_cn, $p_name, $p_mode)
Create an ISelect object containing the available repository for reading or writing.
static default_value($ind, $default, $array)
return default if the value if the value doesn't exist in the array
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...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: ispan.class.php:32
Html Input.
Definition: itext.class.php:30
For the periode tables parm_periode and jrn_periode.
ORM abstract of the table public.stock_change.
ORM abstract of the table public.stock_goods.
Manage the goods.
record_save($p_array)
input($p_array=null, $p_readonly=false)
if an array if receive the keys are p_date p_depot f_idX f_id sg_codeX sg_type0
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
take_last_inventory($p_array)
Return an array, used by Stock_Goods::input.
manage the stocks
Definition: stock.class.php:37
count($p_where="", $p_array=null)
return the number of count in the table corresponding to the where condition
$stock
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition: constant.php:131
const MAX_ARTICLE_STOCK
Definition: constant.php:134
const ATTR_DEF_STOCK
Definition: constant.php:226
$Res
$count
$poste extra