noalyss Version-9
Public Member Functions | Static Public Member Functions
Stock_Goods Class Reference

Manage the goods. More...

+ Inheritance diagram for Stock_Goods:
+ Collaboration diagram for Stock_Goods:

Public Member Functions

 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 More...
 
 record_save ($p_array)
 
 take_last_inventory ($p_array)
 Return an array, used by Stock_Goods::input. More...
 
- Public Member Functions inherited from Stock_Goods_Sql
 __construct ($cn, $p_id=-1)
 
- Public Member Functions inherited from Table_Data_SQL
 __construct ($p_cn, $p_id=-1)
 
 build_query ()
 Build the SQL select statement for querying the object and returns it. More...
 
 column_update ($column_expr, $value)
 update the value of a column with an expression for $value for the current record More...
 
 count ($p_where="", $p_array=null)
 return the number of count in the table corresponding to the where condition More...
 
 delete ()
 
 exist ()
 Count the number of record with the id ,. More...
 
 get_all_to_array ($p_key_col, $p_cond="", $p_array=NULL)
 Get all the row and use the p_key_code are the key value of array. More...
 
 insert ()
 
 load ()
 Load the current row return false if not found. More...
 
 seek ($cond='', $p_array=null)
 retrieve array of object thanks a condition More...
 
 update ()
 
- Public Member Functions inherited from Data_SQL
 __construct (DatabaseCore $p_cn, $p_id=-1)
 
 __toString ()
 
 collect_objects ($cond='', $p_array=null)
 return an array of objects. More...
 
 count ($p_where="", $p_array=null)
 
 delete ()
 
 exist ()
 Count the number of record with the id ,. More...
 
 from_array ($p_array)
 Transform an array into object. More...
 
 get ($p_string)
 get the value thanks the colum name and not the alias (name). More...
 
 get_cn ()
 
 get_info ()
 
 get_name ()
 
 get_object ($p_ret, $idx)
 
 get_pk_value ()
 
 get_primary_key ()
 
 get_type ()
 
 getp ($p_string)
 set the value thanks the alias name instead of the colum name More...
 
 insert ()
 
 load ()
 Load the current row return false if not found. More...
 
 next ($ret, $i)
 get_seek return the next object, the return of the query must have all the column of the object More...
 
 save ()
 Insert or update : if the row already exists, update otherwise insert. More...
 
 seek ($cond='', $p_array=null)
 retrieve array of object thanks a condition More...
 
 set ($p_string, $p_value)
 set the value thanks the colum name and not the alias (name) More...
 
 set_cn ($cn)
 
 set_name ($name)
 
 set_pk_value ($p_value)
 
 set_primary_key ($primary_key)
 
 set_type ($type)
 
 setp ($p_string, $p_value)
 set the value thanks the alias name instead of the colum name More...
 
 to_array ($prefix="")
 Turn an object (row) into an array, and the key could be prefixed with $prefix. More...
 
 to_row ($p_array)
 turns a row fetched from the DB into a SQL object in updating all his attribute More...
 
 update ()
 
 verify ()
 

Static Public Member Functions

static insert_goods (&$p_cn, $p_array)
 Insert into stock_goods from ACH and VEN. More...
 

Additional Inherited Members

- Data Fields inherited from Data_SQL
 $cn
 
 $date_format
 Type of the data. More...
 
 $default
 defaullt date format More...
 
 $name
 Database connection. More...
 
 $primary_key
 Array of logical and real name. More...
 
 $table
 
 $type
 Column name of the primary key. More...
 

Detailed Description

Manage the goods.

Definition at line 36 of file stock_goods.class.php.

Member Function Documentation

◆ input()

Stock_Goods::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

Remarks
$cn database connx
Parameters
$p_arrayif an array if receive the keys are p_date p_depot f_idX f_id sg_codeX sg_type0
$p_readonlytrue or false

Definition at line 56 of file stock_goods.class.php.

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 }
echo_warning($p_string)
warns
Definition: ac_common.php:589
$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.
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
const MAX_ARTICLE_STOCK
Definition: constant.php:134
$poste extra

References Data_SQL\$cn, $date, $e, $fiche, $label, $nb, $p_array, $p_date, $p_readonly, $row, cn, echo_warning(), extra, MAX_ARTICLE_STOCK, HtmlInput\select_stock(), and value.

+ Here is the call graph for this function:

◆ insert_goods()

static Stock_Goods::insert_goods ( $p_cn,
  $p_array 
)
static

Insert into stock_goods from ACH and VEN.

Parameters
type$p_arrayKEY : db => database conx, j_id => jrnx.j_id,goods=> f_id of the goods 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for purchase IN),'repo'=>r_id of the repository (stock_repository.r_id

Definition at line 186 of file stock_goods.class.php.

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 }
global $g_user
if no group available , then stop
$code
catch(Exception $e) $exercice
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition: constant.php:131
const ATTR_DEF_STOCK
Definition: constant.php:226
$Res

References $code, $exercice, $g_user, $p_array, $repo, $Res, ATTR_DEF_STOCK, and NOTFOUND.

Referenced by Acc_Ledger_Purchase\insert(), and Acc_Ledger_Sale\insert().

◆ record_save()

Stock_Goods::record_save (   $p_array)

Definition at line 123 of file stock_goods.class.php.

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 }
isDate($p_date)
Definition: ac_common.php:236
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
h( $row[ 'oa_description'])
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.
$stock
$count

References $a, Data_SQL\$cn, $count, $exercice, $fiche, $i, $nb, $p_array, $per, $periode, $stock, ATTR_DEF_STOCK, h, isDate(), and record_log().

+ Here is the call graph for this function:

◆ take_last_inventory()

Stock_Goods::take_last_inventory (   $p_array)

Return an array, used by Stock_Goods::input.

Remarks
type $cn
Parameters
type$p_array
Exceptions
Exception

Definition at line 228 of file stock_goods.class.php.

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 }
static default_value($ind, $default, $array)
return default if the value if the value doesn't exist in the array
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

References $array, Data_SQL\$cn, $e, $first_day, $p_array, $periode, $result, $stock, $year, Table_Data_SQL\count(), and HtmlInput\default_value().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: