/* * This file is part of PhpCompta. * * PhpCompta is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * PhpCompta is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PhpCompta; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr /*! \file * \brief Functions for the ledger of sold */ require_once("constant.php"); require_once("class_widget.php"); require_once("preference.php"); require_once("fiche_inc.php"); require_once("user_common.php"); /*! FormVenInput \brief Display the form for a sell * Used to show detail, encode a new invoice * or update one * * \param * - p_array which can be empty * - the "journal" * - $p_periode = periode * - view_only if we cannot change it (no right or centralized op) * - $p_article number of article * \return string with the form * TODO Add in parameters the infos about the company for making the invoice */ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_article=1) { if ( $p_array != null ) { // array contains old value foreach ( $p_array as $a=>$v) { ${"$a"}=$v; } } // The date list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); $op_date=( ! isset($e_date) ) ?substr($l_date_start,2,8):$e_date; $e_ech=(isset($e_ech))?$e_ech:""; $e_comm=(isset($e_comm))?$e_comm:""; // $e_jrn=(isset($e_jrn))?$e_jrn:""; // Save old value and set a new one echo_debug('user_form_ven.php',__LINE__,"form_input.php.FormVentep_op_date is $op_date"); $r=""; if ( $pview_only == false) { $r.=JS_SEARCH_CARD; $r.=JS_SHOW_TVA; $r.=JS_TVA; // Compute href $href=$_SERVER['SCRIPT_NAME']; switch ($href) { // user_jrn.php case '/user_jrn.php': $href="user_jrn.php?action=insert_vente&p_jrn=$p_jrn"; break; case '/commercial.php': $href="commercial.php?p_action=facture&p_jrn=$p_jrn"; break; default: echo_error('user_form_ven.php',__LINE__,'Erreur invalid request uri'); exit (-1); } $r.="
"; $r.=JS_CALC_LINE; } else { $r.=""; } return $r; } /*! form_verify_input ************************************************** \brief verify if the data to insert are valid * * parm : * - p_cn database connection * - p_jrn concerned ledger * - User periode * - array with the post data * - p_number number of items * gen : * - * return: */ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) { foreach ($p_array as $name=>$content) { ${"$name"}=$content; } // Verify the date if ( isDate($e_date) == null ) { echo_error("Invalid date $e_date"); echo_debug('user_form_ven.php',__LINE__,"Invalid date $e_date"); echo ""; return null; } // Verify the quantity for ($o = 0;$o < $p_number; $o++) { if ( isNumber(${"e_quant$o"}) == 0 ) { echo_debug('user_form_ven.php',__LINE__,"invalid quantity ".${"e_quant$o"}); echo_error("invalid quantity ".${"e_quant$o"}); echo ""; return null; } // check if vat is correct if ( strlen(trim(${"e_march$o"."_tva_id"})) !=0 and ${"e_march$o"."_tva_id"} != "-1") { // vat is given we check it now check if valid if (isNumber(${"e_march$o"."_tva_id"}) == 0 or CountSql($p_cn,"select tva_id from tva_rate where tva_id=".${"e_march$o"."_tva_id"}) ==0) { $msg="Invalid TVA !!! e_march".$o."_tva_id = ".${"e_march".$o."_tva_id"}; echo_error($msg); echo_error($msg); echo ""; return null; } } } // Verify the ech if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null ) { $msg="Echeance invalide"; echo_error($msg); echo_error($msg); echo ""; return null; } // if ech is a number of days then compute date limit if ( strlen($e_ech) != 0 and isNumber($e_ech) == 1) { list($day,$month,$year)=explode(".",$e_date); echo_debug('user_form_ven.php',__LINE__," date $e_date = $day.$month.$year"); $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year)); echo_debug('user_form_ven.php',__LINE__,"p_ech = $e_ech $p_ech"); $e_ech=$p_ech; $wHidden=new widget("hidden"); $data.=$wHidden->IOValue("e_ech",$e_ech); } // Check if the fiche is in the jrn if (IsFicheOfJrn($p_cn , $p_jrn, $e_client,'deb') == 0 ) { $msg="Client invalid please recheck"; echo_error($msg); echo ""; return null; } // check if all e_march are in fiche for ($i=0;$i<$p_number;$i++) { if ( trim(${"e_march$i"}) == "" ) { // no goods to sell continue; } // Check if ( isFicheOfJrn($p_cn,$p_jrn,${"e_march$i"},'cred') == 0 ) { $msg="Fiche inexistante !!! "; echo_error($msg); echo_error($msg); echo ""; return null; } // check if the ATTR_DEF_ACCOUNT is set $poste=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_ACCOUNT); if ( $poste == null ) { $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable"; echo_error($msg); echo_debug('user_form_ven.php',__LINE__,$msg); echo ""; return null; } if ( strlen(trim($poste))==0 ) { $msg="La fiche ".$tiers." n\'a pas de poste comptable"; echo_error($msg); echo_debug('user_form_ven.php',__LINE__,$msg); echo ""; } } // Verify the userperiode // p_periode contient la periode par default list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); // Date dans la periode active echo_debug ('user_form_ven',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); if ( cmpDate($e_date,$l_date_start)<0 || cmpDate($e_date,$l_date_end)>0 ) { $msg="Not in the active periode please change your preference"; echo_error($msg); echo_error($msg); echo ""; return null; } // Periode ferme if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) { $msg="This periode is closed please change your preference"; echo_error($msg); echo_error($msg); echo ""; return null; } return true; } /*! FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='html',$p_comment='') ************************************************** * \brief Show the invoice before inserting it * the database. * * * \param p_cn database connection * \param p_jrn journal * \param p_periode * \param array of value * \param nb of item * \param p_doc type pdf or html * \return string * */ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form',$p_comment='') { $r=""; $data=""; // Keep all the data if hidden // and store the array in variables $hidden=new widget("hidden"); foreach ($p_array as $name=>$content) { $data.=$hidden->IOValue($name,$content); ${"$name"}=$content; } // start table $r.='| Date : $e_date | "; $r.="||||||
| Client : ".getFicheName($p_cn,$e_client)." | "; $r.="||||||
| Echeance : $e_ech | "; $r.="||||||
| Description : $e_comm | "; $r.="||||||
| Article | "; $r.="quantité | "; $r.="prix unit. | "; $r.="taux tva | "; $r.="Montant HTVA | "; $r.="Montant TVA | "; $r.="Total | "; $r.="
|---|---|---|---|---|---|---|
| '.$fiche_name.' | '; $r.=''.$fiche_quant.' | '; $r.=''.$fiche_price.' | '; $r.="$vat_label | "; $r.=''.round($fiche_sum,2).' | '; $r.=''.round($fiche_amount_vat,2).' | '; $r.=''.round($fiche_with_vat,2).' | '; $r.="