Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 require_once 'class_stock_goods_sql.php';
00029
00030 class Stock_Goods extends Stock_Goods_Sql
00031 {
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 function input($p_array = null, $p_readonly = false)
00051 {
00052 global $cn;
00053
00054 if ($p_array != null)
00055 {
00056 extract($p_array);
00057 }
00058 else
00059 {
00060 $p_date = '';
00061 $p_motif = '';
00062 $p_depot = 0;
00063 }
00064 $date = new IDate('p_date', $p_date);
00065 $date->setReadOnly($p_readonly);
00066 $motif = new IText('p_motif', $p_motif);
00067 $motif->setReadOnly($p_readonly);
00068 $motif->size = 80;
00069 $idepo = HtmlInput::select_stock($cn, "p_depot", "W");
00070 $idepo->setReadOnly($p_readonly);
00071 if (count($idepo->value) == 0)
00072 {
00073 NoAccess();
00074 exit();
00075 }
00076 $idepo->selected = $p_depot;
00077 if ($p_readonly ) {
00078 $nb=$row;
00079 } else {
00080 if (isset ($row ) )
00081 {
00082 $nb=($row > MAX_ARTICLE_STOCK)?$row:MAX_ARTICLE_STOCK;
00083 }else {
00084 $nb=MAX_ARTICLE_STOCK;
00085 }
00086 }
00087 for ($e = 0; $e < $nb; $e++)
00088 {
00089 $sg_code[$e] = new ICard('sg_code' . $e);
00090 $sg_code[$e]->extra = "[sql] fd_id = 500000";
00091 $sg_code[$e]->set_attribute("typecard", $sg_code[$e]->extra);
00092 $sg_code[$e]->set_attribute("label", "label" . $e);
00093 $sg_code[$e]->value = (isset(${'sg_code' . $e})) ? ${'sg_code' . $e} : '';
00094 $sg_quantity[$e] = new INum('sg_quantity' . $e);
00095 $sg_quantity[$e]->value = (isset(${'sg_quantity' . $e})) ? ${'sg_quantity' . $e} : '';
00096 $label[$e] = new ISpan("label$e");
00097 if (trim($sg_code[$e]->value) != '')
00098 {
00099 $label[$e]->value = $cn->get_value("select vw_name from vw_fiche_attr where quick_code=$1", array($sg_code[$e]->value));
00100 }
00101 $sg_code[$e]->setReadOnly($p_readonly);
00102 $sg_quantity[$e]->setReadOnly($p_readonly);
00103 if ( isset (${'sg_type'.$e})) {
00104 $sg_type[$e]=(${'sg_type'.$e}=='c')?'OUT':'IN';
00105 }
00106 if ( isset (${'f_id'.$e})) {
00107 $fiche[$e]=new Fiche($this->cn,${'f_id'.$e});
00108 }
00109 }
00110 require_once 'template/stock_inv.php';
00111 }
00112
00113 function record_save($p_array)
00114 {
00115 global $cn;
00116 try
00117 {
00118 if (isDate($p_array['p_date']) == null)
00119 throw new Exception('Date invalide');
00120 $cn->start();
00121 $ch = new Stock_Change_Sql($cn);
00122 $ch->setp("c_comment", $p_array['p_motif']);
00123 $ch->setp("r_id", $p_array['p_depot']);
00124 $ch->setp("c_date", $p_array['p_date']);
00125 $ch->setp('tech_user', $_SESSION['g_user']);
00126 $ch->insert();
00127 $per = new Periode($cn);
00128 $periode = $per->find_periode($p_array['p_date']);
00129 $exercice = $per->get_exercice($periode);
00130 $nb=$p_array['row'];
00131 for ($i = 0; $i < $nb; $i++)
00132 {
00133 $a = new Stock_Goods_Sql($cn);
00134 if ($p_array['sg_quantity' . $i] != 0 &&
00135 trim($p_array['sg_code' . $i]) != '')
00136 {
00137 $stock= strtoupper(trim($p_array['sg_code' . $i]));
00138 $fiche=new Fiche($cn);
00139 $fiche->get_by_qcode($p_array['sg_code' . $i]);
00140
00141
00142
00143 $count=$cn->get_value('select count(*) from fiche_detail where ad_id=$1 and ad_value=$2',
00144 array(ATTR_DEF_STOCK,$stock));
00145 if ( $count==0) {
00146 throw new Exception("Code stock inexistant");
00147 }
00148 $a->f_id=$fiche->id;
00149 $a->sg_code = $stock;
00150 $a->sg_quantity = abs($p_array['sg_quantity' . $i]);
00151 $a->sg_type = ($p_array['sg_quantity' . $i] > 0) ? 'd' : 'c';
00152 $a->sg_comment = $p_array['p_motif'];
00153 $a->tech_user = $_SESSION['g_user'];
00154 $a->r_id = $p_array['p_depot'];
00155 $a->sg_exercice = $exercice;
00156 $a->c_id = $ch->c_id;
00157 $a->sg_date=$p_array['p_date'];
00158 $a->insert();
00159 }
00160 }
00161 $cn->commit();
00162 }
00163 catch (Exception $exc)
00164 {
00165 echo $exc->getTraceAsString();
00166 throw $exc;
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175 static function insert_goods(&$p_cn,$p_array)
00176 {
00177 global $g_user;
00178 extract ($p_array);
00179 if ($g_user->can_write_repo($repo) == false)
00180 return false;
00181
00182
00183 $code = new Fiche($p_cn);
00184 $code->get_by_qcode($goods);
00185 $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK);
00186 if ($code_marchandise == NOTFOUND || $code_marchandise=='')
00187 return false;
00188
00189 $exercice = $g_user->get_exercice();
00190
00191 if ($exercice == 0)
00192 throw new Exception('Annee invalide erreur');
00193
00194 $Res = $p_cn->exec_sql("insert into stock_goods (
00195 j_id,
00196 f_id,
00197 sg_code,
00198 sg_quantity,
00199 sg_type,sg_exercice,r_id ) values ($1,$2,$3,$4,$5,$6,$7)", array(
00200 $p_array['j_id'],
00201 $code->id,
00202 $code_marchandise,
00203 $p_array['quant'],
00204 $p_array['dir'],
00205 $exercice,
00206 $p_array['repo']
00207 )
00208 );
00209 return $Res;
00210 }
00211
00212 }
00213
00214 ?>