diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php
index ac353478aac..5b0d0bf9ee6 100644
--- a/htdocs/fourn/facture/fiche.php
+++ b/htdocs/fourn/facture/fiche.php
@@ -117,17 +117,30 @@ if ($_POST['action'] == 'update' && ! $_POST['cancel'])
$result = $db->query( $sql);
}
/*
- * Action cr�ation
+ * Action creation
*/
if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
{
- if ($_POST['facnumber'])
+ $datefacture=dolibarr_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
+ $datedue=dolibarr_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
+
+ if ($datefacture == '')
{
- $datefacture = dolibarr_mktime(12,0,0,
- $_POST['remonth'],
- $_POST['reday'],
- $_POST['reyear']);
+ $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ $error++;
+ }
+ if (empty($_POST['facnumber']))
+ {
+ $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
';
+ $_GET['action']='create';
+ $_GET['socid']=$_POST['socid'];
+ $error++;
+ }
+ if (! $error)
+ {
$db->begin();
// Creation facture
@@ -137,7 +150,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
$facfou->socid = $_POST['socid'];
$facfou->libelle = $_POST['libelle'];
$facfou->date = $datefacture;
- $facfou->date_echeance = dolibarr_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
+ $facfou->date_echeance = $datedue;
$facfou->note = $_POST['note'];
$facid = $facfou->create($user);
@@ -190,12 +203,6 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer)
$_GET['socid']=$_POST['socid'];
}
}
- else
- {
- $mesg=''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
';
- $_GET['action']='create';
- $_GET['socid']=$_POST['socid'];
- }
}
if ($_GET['action'] == 'del_ligne')
@@ -337,11 +344,17 @@ if ($_GET['action'] == 'create' or $_GET['action'] == 'copy')
$societe->fetch($_GET['socid']);
}
+ $datefacture=dolibarr_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
+ $datedue=dolibarr_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
+
+ $dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datefacture);
+
print '