diff --git a/include/form_input.php b/include/form_input.php
index fa8d0cc83..71fcbcfc8 100644
--- a/include/form_input.php
+++ b/include/form_input.php
@@ -31,7 +31,8 @@ include_once("user_common.php");
* - Default Value
* - View_only
* - $p_list for the select, give the possible values item[0] is the val and item[1]
- * is the label
+ * is the label or for the js_search p_list is a string (cred
+ * or deb or the fiche_def_type
* gen :
* - None
* return: string
@@ -45,7 +46,7 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
$hidden=(strlen($p_name) != 0) ?" ":"";
// return
- return "
$p_label $hidden $p_value ";
+ return " $p_label $hidden $p_value ";
} else {
// name and value are set put the info in a hidden field
$hidden=(strlen($p_name) != 0) ?" ":"";
@@ -73,13 +74,30 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
// input type == TEXT
if ( strtolower($p_type)=="text") {
- $r=sprintf('%s ',
+ $r=sprintf('%s ',
$p_label,
$p_type,
$p_name,
$p_value);
return $r;
}
+ // input type == TEXT_BIG
+ if ( strtolower($p_type)=="text_big") {
+ $r=sprintf('%s ',
+ $p_label,
+ $p_type,
+ $p_name,
+ $p_value);
+ return $r;
+ }
+
+ //span
+ if ( strtolower($p_type)=="span") {
+ $r=sprintf('%s ',
+ $p_name,
+ $p_value);
+ return $r;
+ }
// input type == HIDDEN
if ( strtolower($p_type)=="hidden") {
@@ -90,6 +108,30 @@ function InputType($p_label,$p_type,$p_name,$p_value,$p_viewonly=false,$p_list=n
return $r;
}
+ // input type == js_search => button search
+ if ( strtolower($p_type)=="js_search") {
+ $l_sessid=(isset ($_POST['PHPSESSID']))?$_POST['PHPSESSID']:$_GET['PHPSESSID'];
+ $r=sprintf('
+
+
+ %s
+
+
+ ',
+ $l_sessid,
+ $p_list,
+ $p_name,
+ $l_sessid,
+ $p_list,
+ $p_name,
+ $p_label,
+ $p_name,
+ $p_value
+ );
+
+ return $r;
+ }
+
}
/* function FormVente
@@ -126,7 +168,10 @@ function FormVente($p_cn,$p_jrn,$p_user,$p_array=null,$view_only=true,$p_article
echo_debug("form_input.php.FormVentep_op_date is $op_date");
$r="";
if ( $view_only == false) {
- $r="";
@@ -231,7 +322,14 @@ if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null
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);
@@ -241,7 +339,39 @@ if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null
$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,'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 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"},'cred') == 0 ) {
+ $msg="Fiche inexistante !!! ";
+ echo_error($msg); echo_error($msg);
+ echo "";
+ return null;
+ }
+ }
+
// Verify the userperiode
// userPref contient la periode par default
@@ -295,26 +425,42 @@ if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null
$r.="Total ";
$r.="";
for ($i=0;$i<$p_number;$i++) {
+ if ( trim(${"e_march$i"}) == "" ) {
+ // no goods to sell
+ continue;
+ }
+
+ // Get the name
$fiche_name=getFicheName($p_cn,${"e_march$i"});
- $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE);
+ // Quantity
$fiche_quant=${"e_quant$i"};
// No row if there is quantity
if ( $fiche_quant == 0.0 ) continue;
+
+
+ // If the price is not a number, retrieve the price from the database
+ if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
+ $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE);
+ } else {
+ $fiche_price=${"e_march$i"."_sell"};
+ }
+
+
// VAT
$vat=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA);
- // vat label
- // vat rate
- $a_vat=GetTvaRate($p_cn,$vat);
- if ( $a_vat == null ) {
- $vat_label="unknown";
- $vat_rate=0.0;
- } else {
- $vat_label=$a_vat['tva_label'];
- $vat_rate=$a_vat['tva_rate'];
- }
+ // vat label
+ // vat rate
+ $a_vat=GetTvaRate($p_cn,$vat);
+ if ( $a_vat == null ) {
+ $vat_label="unknown";
+ $vat_rate=0.0;
+ } else {
+ $vat_label=$a_vat['tva_label'];
+ $vat_rate=$a_vat['tva_rate'];
+ }
// Total card without vat
$fiche_sum=$fiche_price*$fiche_quant;
@@ -349,14 +495,20 @@ if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null
if ( $p_doc == 'html' ) {
$r.='';
}
if ( $p_doc == 'pdf' ) {
- $r.='';
@@ -378,10 +530,13 @@ if ( $p_doc == 'pdf' ) {
* nb_item => e : 3
* e_march0 => e : 6
* e_quant0 => e : 0
+ * e_march0_sell=>e:1
* e_march1 => e : 6
* e_quant1 => e : 2
+ * e_march1_sell=>e:1
* e_march2 => e : 7
* e_quant2 => e : 3
+ * e_march2_sell=>e:1
V : view_invoice => e : Voir cette facture
V : record_invoice => e : Sauver
* - $p_user userid
@@ -393,28 +548,39 @@ V : record_invoice => e : Sauver
*/
function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn)
{
- foreach ( $p_array as $v => $e)
- {
- ${"$v"}=$e;
- }
- // Get the default period
- $periode=GetUserPeriode($p_cn,$p_user);
- $amount=0.0;
- // Computing total customer
- for ($i=0;$i<$nb_item;$i++) {
- // store quantity & goods in array
- $a_good[$i]=${"e_march$i"};
- $a_quant[$i]=${"e_quant$i"};
- $amount+=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE)*$a_quant[$i];
- }
- $a_vat=ComputeVat($p_cn, $a_good,$a_quant,ATTR_DEF_PRIX_VENTE);
- $sum_vat=0.0;
- foreach ( $a_vat as $element => $t) {
- echo_debug(" a_vat element $element t $t");
- $sum_vat+=$t;
- echo_debug("sum_vat = $sum_vat");
- }
- // First we add in jrnx
+ foreach ( $p_array as $v => $e)
+ {
+ ${"$v"}=$e;
+ }
+ // Get the default period
+ $periode=GetUserPeriode($p_cn,$p_user);
+ $amount=0.0;
+ // Computing total customer
+ for ($i=0;$i<$nb_item;$i++) {
+ // store quantity & goods in array
+ $a_good[$i]=${"e_march$i"};
+ $a_quant[$i]=${"e_quant$i"};
+
+ // check wether the price is set or no
+ if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
+ // If the price is not set we have to find it from the database
+ $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE);
+ } else {
+ // The price is valid
+ $a_price[$i]=${"e_march$i"."_sell"};
+ }
+ $amount+=$a_price[$i]*$a_quant[$i];
+ }
+
+ $a_vat=ComputeVat($p_cn, $a_good,$a_quant,$a_price);
+
+ $sum_vat=0.0;
+ foreach ( $a_vat as $element => $t) {
+ echo_debug(" a_vat element $element t $t");
+ $sum_vat+=$t;
+ echo_debug("sum_vat = $sum_vat");
+ }
+ // First we add in jrnx
// Compute the j_grpt
$seq=GetNextId($p_cn,'j_grpt')+1;
@@ -427,14 +593,22 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn)
// Credit = goods
for ( $i = 0; $i < $nb_item;$i++) {
$poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT);
-
- InsertJrnx($p_cn,'c',$p_user,$p_jrn,$poste,$e_date,$amount,$seq,$periode);
- }
+
+ // don't record operation of 0
+ if ( $a_price[$i]*$a_quant[$i] == 0 ) continue;
+
+ // record into jrnx
+ $j_id=InsertJrnx($p_cn,'c',$p_user,$p_jrn,$poste,$e_date,$a_price[$i]*$a_quant[$i],$seq,$periode);
+
+ // always save quantity but in withStock we can find what card need a stock management
+ InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c');
+ }
// Insert Vat
if (sizeof($a_vat) != 0 ) // no vat
{
foreach ($a_vat as $tva_id => $tva_amount ) {
$poste=GetTvaPoste($p_cn,$tva_id,'c');
+ if ($tva_amount == 0 ) continue;
InsertJrnx($p_cn,'c',$p_user,$p_jrn,$poste,$e_date,$tva_amount,$seq,$periode);
}
}
@@ -476,28 +650,55 @@ function FormAch($p_cn,$p_jrn,$p_user,$p_submit,$p_array=null,$view_only=true,$p
// The date
$userPref=GetUserPeriode($p_cn,$p_user);
list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref);
- $op_date=( ! isset($e_date) ) ? "01".substr($l_date_start,2,8):$e_date;
+ $e_date=( ! isset($e_date) ) ? "01".substr($l_date_start,2,8):$e_date;
$e_ech=(isset($e_ech))?$e_ech:"";
+ $e_comment=(isset($e_comment))?$e_comment:"";
// Save old value and set a new one
- echo_debug("form_input.php.FormAch p_op_date is $op_date");
+ // echo_debug("form_input.php.FormAch p_op_date is $e_date");
$r="";
if ( $view_only == false) {
- $r="