/* * 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: 1.1 $ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr require_once("constant.php"); require_once("class_widget.php"); require_once("preference.php"); require_once("fiche_inc.php"); require_once("user_common.php"); /* function FormAchInput * Purpose : Display the form for a sell * Used to show detail, encode a new invoice * or update one * * parm : * - 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 * gen : * - * return: string with the form * TODO Add in parameters the infos about the company for making the invoice */ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_only=true,$p_article=1) { if ( $p_array != null ) { // array contains old value extract($p_array); } // 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(__FILE__,__LINE__,"form_input.php.FormSell_op_date is $op_date"); $r=""; if ( $pview_only == false) { $r.=JS_SEARCH_CARD; $r.=JS_SHOW_TVA; $r.=JS_TVA; $r.="
"; } else { $r.=""; } return $r; } /* function form_verify_input ************************************************** * Purpose : 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(__FILE__,__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(__FILE__,__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; } // Verify is a client is set if ( isNumber($e_client) == 0) { $msg="Client inexistant"; 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(__FILE__,__LINE__," date $e_date = $day.$month.$year"); $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year)); echo_debug(__FILE__,__LINE__,"p_ech = $e_ech $p_ech"); $e_ech=$p_ech; $data.=InputType("","HIDDEN","e_ech",$e_ech); } // Check if the fiche is in the jrn if (IsFicheOfJrn($p_cn , $p_jrn, $e_client,'cred') == 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 wether the f_id is a number if ( isNumber(${"e_march$i"}) == 0 ) { $msg="Fiche inexistante !!! "; echo_error($msg); echo_error($msg); echo ""; return null; } // Check if ( isFicheOfJrn($p_cn,$p_jrn,${"e_march$i"},'deb') == 0 ) { $msg="Fiche inexistante !!! "; echo_error($msg); echo_error($msg); echo ""; return null; } } // 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 ("date start periode $l_date_start date fin periode $l_date_end date demand� $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 ferm� 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; } /* function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='html',$p_comment='') ************************************************** * Purpose : Show the invoice before inserting it * the database * * parm : * - p_cn database connection * - p_jrn journal * - p_periode * - array of value * - nb of item * - p_doc type pdf or html * gen : * - none * return: * - string * */ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_piece=true) { $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.="