noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_stock_goods.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /**
00024  * @file
00025  * @brief Manage the goods
00026  *
00027  */
00028 require_once 'class_stock_goods_sql.php';
00029 
00030 class Stock_Goods extends Stock_Goods_Sql
00031 {
00032 /**
00033  * if an array if receive the keys are
00034  *  p_date
00035  *  p_depot
00036  *  f_idX f_id
00037  *  sg_codeX
00038  *  sg_type0
00039  *
00040  * @global $cn database connx
00041  * @param $p_array
00042  * if an array if receive the keys are
00043  *  p_date
00044  *  p_depot
00045  *  f_idX f_id
00046  *  sg_codeX
00047  *  sg_type0
00048  * @param $p_readonly true or false
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                 {//ATTR_DEF_STOCKfiche_
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                                          * check if code stock does exist
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          * Insert into stock_goods from ACH and VEN
00171          * @param type $p_array KEY : db => database conx, j_id => jrnx.j_id,goods=> f_id of the goods
00172          * 'quant' => quantity ,'dir'=> d or c (c for sales OUT and d for purchase IN),'repo'=>r_id of the
00173          * repository (stock_repository.r_id
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             // Retrieve the good account for stock
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 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations