diff --git a/include/fiche_inc.php b/include/fiche_inc.php index a8a255910..63e64d3aa 100644 --- a/include/fiche_inc.php +++ b/include/fiche_inc.php @@ -1453,7 +1453,7 @@ function getFicheAttribut($p_cn,$p_id,$p_attr="") { where f_id=$p_id and ad_id=$p_attr"); - if ( pg_NumRows($Res) == 0 ) return "Unknown"; + if ( pg_NumRows($Res) == 0 ) return NULL; $st=pg_fetch_array($Res,0); return $st['av_text']; } else { diff --git a/include/user_action_ach.php b/include/user_action_ach.php index b9ab3b3bc..a5d3fa73b 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -101,7 +101,7 @@ if ( $action == 'new' ) { // if something goes wrong, correct it $submit=' '; - $r=FormAchInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$submit,$HTTP_POST_VARS, $nb_number); + $r=FormAchInput($cn,$_GET['p_jrn'],$User->GetPeriode(),$HTTP_POST_VARS,$submit, false, $nb_number); } echo '
'; echo $r; diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 0a1f5674f..488c94f89 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -40,7 +40,7 @@ require_once("user_common.php"); */ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_only=true,$p_article=1) { - +echo_debug(__FILE__,__LINE__,"Enter FormAchInput($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$pview_only,$p_article"); if ( $p_array != null) { // array contains old value extract($p_array); @@ -247,6 +247,7 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ */ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) { +echo_debug(__FILE__,__LINE__,"Enter form_verify_input $p_cn,$p_jrn,$p_periode,".var_export($p_array,true).",$p_number"); foreach ($p_array as $name=>$content) { ${"$name"}=$content; } @@ -341,6 +342,24 @@ for ($o = 0;$o < $p_number; $o++) { echo ""; return null; } + // check if the ATTR_DEF_ACCOUNT is set + $poste=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_ACCOUNT); + echo_debug(__FILE__,__LINE__,"poste value = ".$poste."size = ".strlen(trim($poste))); + if ( $poste == null ) + { + $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable"; + echo_error($msg); echo_debug(__FILE__,__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(__FILE__,__LINE__,$msg); + echo ""; + return null; + } } // Verify the userperiode @@ -348,7 +367,7 @@ for ($o = 0;$o < $p_number; $o++) { 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"); + echo_debug ("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 ) { diff --git a/include/user_form_fin.php b/include/user_form_fin.php index 7cee66115..7679f66d1 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -156,29 +156,55 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $tiers_label=""; $tiers_amount=(isset(${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0; if ( isNumber($tiers_amount) == 0) { - if ( $pview_only==true ){ - $msg="Montant invalide !!! "; - echo_error($msg); echo_error($msg); - echo ""; - return null; - } - $tiers_amount=0; + if ( $pview_only==true ) + { + $msg="Montant invalide !!! "; + echo_error($msg); echo_error($msg); + echo ""; + return null; + } + $tiers_amount=0; } $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:""; // If $tiers has a value - if ( isNumber($tiers) == 1 ) { - if ( isFicheOfJrn($p_cn,$p_jrn,$tiers,'cred') == 0 ) { - $msg="Fiche inexistante !!! "; - echo_error($msg); echo_error($msg); - echo ""; - $tiers=""; - } else { - // retrieve the tva label and name - $a_fiche=GetFicheAttribut($p_cn, $tiers); - if ( $a_fiche != null ) { - $tiers_label=$a_fiche['vw_name']; - } - } + if ( isNumber($tiers) == 1 ) + { + if ( $pview_only && isFicheOfJrn($p_cn,$p_jrn,$tiers,'cred') == 0 ) + { + $msg="Fiche inexistante !!! "; + echo_error($msg); echo_debug(__FILE__,__LINE__,$msg); + echo ""; + $tiers=""; + return null; + } + else + { + // retrieve the tva label and name + $a_fiche=GetFicheAttribut($p_cn, $tiers); + if ( $a_fiche != null ) { + $tiers_label=$a_fiche['vw_name']; + } + } + // if the parameter is set to view only we do not check + if ( $pview_only ) + { + // check if the ATTR_DEF_ACCOUNT is set + $poste=GetFicheAttribut($p_cn,$tiers,ATTR_DEF_ACCOUNT); + if ( $poste == null ) + { + $msg="La fiche ".$tiers." n\'a pas poste comptable"; + echo_error($msg);echo_debug(__FILE__,__LINE__,$msg); + echo ""; + return null; + } + if ( strlen(trim($poste))==0 ) + { + $msg="La fiche ".$tiers." n\'a pas poste comptable"; + echo_error($msg); echo_debug(__FILE__,__LINE__,$msg); + echo ""; + return null; + } + } } ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0; diff --git a/include/user_form_ven.php b/include/user_form_ven.php index d4b4de0d6..9c4043358 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -354,6 +354,23 @@ for ($o = 0;$o < $p_number; $o++) { 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(__FILE__,__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(__FILE__,__LINE__,$msg); + echo ""; + } + } // Verify the userperiode @@ -683,10 +700,10 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) $vat_code=$a_vat[$i]; } $r=ExecSql($p_cn,"insert into quant_sold". - "(qs_internal,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code) values". - "('".$internal."',".$a_good[$i].",".$a_quant[$i].",".$a_price[$i]. + "(qs_internal,qs_fiche,qs_quantite,qs_price,qs_vat,qs_vat_code,qs_client) values". + "('".$internal."',".$a_good[$i].",".$a_quant[$i].",".$a_price[$i]*$a_quant[$i]. ",".$computed_vat. - ",".$vat_code.")"); + ",".$vat_code.",".$e_client.")"); if ( $r == false ) { Rollback($p_cn); exit(" Error __FILE__ __LINE__"); }; } Commit($p_cn);