'.$langs->trans('Date').' ';
print ''.dolibarr_print_date($fac->date,'daytext').' ';
-
+
$nbrows=8;
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++;
if ($conf->projet->enabled) $nbrows++;
-
+
print '';
-
+
/*
- * Liste des paiements
- */
+ * Liste des paiements
+ */
$sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
$sql.= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
@@ -2083,7 +2111,7 @@ else
$num = $db->num_rows($result);
$i = 0;
print '';
-
+
// Liste des paiements ou remboursements
print '';
print ''.($fac->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).' ';
@@ -2108,7 +2136,7 @@ else
print ' ';
$i++;
}
-
+
// Already payed
print ''.$langs->trans('AlreadyPayed').' : '.price($totalpaye).' '.$langs->trans('Currency'.$conf->monnaie).' ';
@@ -2117,18 +2145,18 @@ else
$resteapayeraffiche=$resteapayer;
// Boucle sur chaque facture avoir appliquee
- $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
+ $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
$sql.= " re.description, re.fk_facture_source, re.fk_facture_source";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
- $sql.= " WHERE fk_facture = ".$fac->id;
- $resql=$db->query($sql);
- if ($resql)
+ $sql.= " WHERE fk_facture = ".$fac->id;
+ $resql=$db->query($sql);
+ if ($resql)
{
- $num = $db->num_rows($resql);
- $i = 0;
+ $num = $db->num_rows($resql);
+ $i = 0;
$invoice=new Facture($db);
- while ($i < $num)
- {
+ while ($i < $num)
+ {
$obj = $db->fetch_object($resql);
$invoice->fetch($obj->fk_facture_source);
print ''.$langs->trans("CreditNote").' ';
@@ -2145,7 +2173,7 @@ else
{
dolibarr_print_error($db);
}
-
+
// Payé partiellement 'escompte'
if (($fac->statut == 2 || $fac->statut == 3) && $fac->close_code == 'discount_vat')
{
@@ -2200,9 +2228,9 @@ else
{
dolibarr_print_error($db);
}
-
+
print ' ';
-
+
// Date limite reglement
print '';
print ''.$langs->trans('DateMaxPayment').' ';
@@ -2217,7 +2245,7 @@ else
print ' ';
}
print ' ';
-
+
// Conditions de règlement
print '';
print '';
@@ -2260,17 +2288,17 @@ else
$html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none');
}
print ' ';
-
+
// Lit lignes de facture pour déterminer montant
// On s'en sert pas mais ca sert pour debuggage
/*
- $sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,';
- $sql .= ' l.remise_percent, l.subprice';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l ';
- $sql .= ' WHERE l.fk_facture = '.$fac->id;
- $resql = $db->query($sql);
- if ($resql)
- {
+ $sql = 'SELECT l.price as price, l.qty, l.rowid, l.tva_taux,';
+ $sql .= ' l.remise_percent, l.subprice';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as l ';
+ $sql .= ' WHERE l.fk_facture = '.$fac->id;
+ $resql = $db->query($sql);
+ if ($resql)
+ {
$num_lignes = $db->num_rows($resql);
$i=0;
$total_lignes_ht=0;
@@ -2278,18 +2306,18 @@ else
$total_lignes_ttc=0;
while ($i < $num_lignes)
{
- $obj=$db->fetch_object($resql);
- $ligne_ht=($obj->price*$obj->qty);
- $ligne_vat=($ligne_ht*$obj->tva_taux/100);
- $ligne_ttc=($ligne_ht+$ligne_vat);
- $total_lignes_ht+=$ligne_ht;
- $total_lignes_vat+=$ligne_vat;
- $total_lignes_ttc+=$ligne_ttc;
- $i++;
+ $obj=$db->fetch_object($resql);
+ $ligne_ht=($obj->price*$obj->qty);
+ $ligne_vat=($ligne_ht*$obj->tva_taux/100);
+ $ligne_ttc=($ligne_ht+$ligne_vat);
+ $total_lignes_ht+=$ligne_ht;
+ $total_lignes_vat+=$ligne_vat;
+ $total_lignes_ttc+=$ligne_ttc;
+ $i++;
}
- }
- */
-
+ }
+ */
+
// Montants
print ''.$langs->trans('AmountHT').' ';
print ''.price($fac->total_ht).' ';
@@ -2298,18 +2326,18 @@ else
print ''.$langs->trans('Currency'.$conf->monnaie).' ';
print ''.$langs->trans('AmountTTC').' '.price($fac->total_ttc).' ';
print ''.$langs->trans('Currency'.$conf->monnaie).' ';
-
+
// Statut
print ''.$langs->trans('Status').' ';
print ''.($fac->getLibStatut(4,$totalpaye)).' ';
-
+
// Projet
if ($conf->projet->enabled)
{
$langs->load('projects');
print '';
print '';
-
+
print '';
print $langs->trans('Project');
print ' ';
@@ -2320,7 +2348,7 @@ else
print '';
}
print '
';
-
+
print ' ';
if ($_GET['action'] == 'classer')
{
@@ -2338,8 +2366,8 @@ else
/*
- * Lignes de factures
- */
+ * Lignes de factures
+ */
$sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_taux,';
$sql.= ' l.fk_remise_except,';
$sql.= ' l.remise_percent, l.subprice, l.info_bits,';
@@ -2389,7 +2417,7 @@ else
{
print ' ';
print ' '; // ancre pour retourner sur la ligne
-
+
// Affiche ligne produit
$text = '';
if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service');
@@ -2411,7 +2439,7 @@ else
{
print ' ';
print ' '; // ancre pour retourner sur la ligne
-
+
if (($objp->info_bits & 2) == 2)
{
print '';
@@ -2589,9 +2617,9 @@ else
dolibarr_print_error($db);
}
- /*
- * Ajouter une ligne
- */
+ /*
+ * Ajouter une ligne
+ */
if ($fac->statut == 0 && $user->rights->facture->creer && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline')
{
print '';
@@ -2664,7 +2692,7 @@ else
print ''.$langs->trans('ReductionShort').' ';
print ' ';
print ' ';
-
+
print ' ';
print ' ';
@@ -2721,27 +2749,27 @@ else
/*
- * Boutons actions
- */
+ * Boutons actions
+ */
if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
- {
+ {
if ($user->societe_id == 0 && $_GET['action'] <> 'valid' && $_GET['action'] <> 'editline')
{
print '';
-
+
// Editer une facture déjà validée, sans paiement effectué et pas exporté en compta
if ($fac->statut == 1)
{
// On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées
$ventilExportCompta = $fac->getVentilExportCompta();
-
+
if ($conf->global->FACTURE_ENABLE_EDITDELETE && $user->rights->facture->modifier
- && ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0))
+ && ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0))
{
print '
'.$langs->trans('Modify').' ';
}
}
-
+
// Récurrente
if (! $conf->global->FACTURE_DISABLE_RECUR && $fac->type == 0)
{
@@ -2750,7 +2778,7 @@ else
print '
'.$langs->trans("ChangeIntoRepeatableInvoice").' ';
}
}
-
+
// Valider
if ($fac->statut == 0 && $num_lignes > 0 && (($fac->type < 2 && $fac->total_ttc >= 0) || ($fac->type == 2 && $fac->total_ttc <= 0)))
{
@@ -2759,7 +2787,7 @@ else
print '
id.'&action=valid">'.$langs->trans('Validate').' ';
}
}
-
+
// Envoyer
if (($fac->statut == 1 || $fac->statut == 2) && $user->rights->facture->envoyer)
{
@@ -2772,7 +2800,7 @@ else
print '
'.$langs->trans('SendByMail').' ';
}
}
-
+
// Envoyer une relance
if (($fac->statut == 1 || $fac->statut == 2) && $resteapayer > 0 && $user->rights->facture->envoyer)
{
@@ -2785,7 +2813,7 @@ else
print '
'.$langs->trans('SendRemindByMail').' ';
}
}
-
+
// Emettre paiement
if ($fac->type != 2 && $fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement)
{
@@ -2805,7 +2833,7 @@ else
}
}
}
-
+
// Emettre remboursement ou Convertir en reduc
if ($fac->type == 2)
{
@@ -2813,23 +2841,23 @@ else
{
print '
'.$langs->trans('DoPaymentBack').' ';
}
-
+
if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->creer && $fac->getSommePaiement() == 0)
{
print '
id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').' ';
}
}
-
+
// Classer 'payé'
if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement &&
- (($fac->type != 2 && $resteapayer <= 0) || ($fac->type == 2 && $resteapayer >= 0)) )
+ (($fac->type != 2 && $resteapayer <= 0) || ($fac->type == 2 && $resteapayer >= 0)) )
{
print '
'.$langs->trans('ClassifyPayed').' ';
}
-
+
// Classer 'fermée' (possible si validée et pas encore classée payée)
if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
- && $user->rights->facture->paiement)
+ && $user->rights->facture->paiement)
{
if ($totalpaye > 0 || $totalavoir > 0)
{
@@ -2848,7 +2876,7 @@ else
}
}
}
-
+
// Supprimer
if ($fac->is_erasable() && $user->rights->facture->supprimer && $_GET['action'] != 'delete')
{
@@ -2861,39 +2889,39 @@ else
print '
id.'&action=delete">'.$langs->trans('Delete').' ';
}
}
-
+
print '
';
}
}
-
-
+
+
if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend')
{
print '';
print ' '; // ancre
-
+
/*
- * Documents générés
- */
+ * Documents générés
+ */
$filename=sanitize_string($fac->ref);
$filedir=$conf->facture->dir_output . '/' . sanitize_string($fac->ref);
$urlsource=$_SERVER['PHP_SELF'].'?facid='.$fac->id;
$genallowed=$user->rights->facture->creer;
$delallowed=$user->rights->facture->supprimer;
-
+
$var=true;
-
+
print ' ';
$somethingshown=$formfile->show_documents('facture',$filename,$filedir,$urlsource,$genallowed,$delallowed,$fac->modelpdf);
-
+
/*
- * Propales rattachées
- */
+ * Propales rattachées
+ */
$sql = 'SELECT '.$db->pdate('p.datep').' as dp, p.total_ht, p.ref, p.ref_client, p.rowid as propalid';
$sql .= ' FROM '.MAIN_DB_PREFIX.'propal as p';
$sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp";
$sql .= " WHERE fp.fk_propal = p.rowid AND fp.fk_facture = ".$fac->id;
-
+
dolibarr_syslog("facture.php: sql=".$sql);
$resql = $db->query($sql);
if ($resql)
@@ -2912,7 +2940,7 @@ else
print ' '.$langs->trans('Date').' ';
print ''.$langs->trans('AmountHT').' ';
print ' ';
-
+
$var=True;
while ($i < $num)
{
@@ -2939,10 +2967,10 @@ else
{
dolibarr_print_error($db);
}
-
+
/*
- * Commandes rattachées
- */
+ * Commandes rattachées
+ */
if($conf->commande->enabled)
{
$sql = 'SELECT '.$db->pdate('c.date_commande').' as date_commande, c.total_ht, c.ref, c.ref_client, c.rowid as id';
@@ -2954,7 +2982,7 @@ else
if ($num)
{
$langs->load("orders");
-
+
$i = 0; $total = 0;
if ($somethingshown) print ' ';
$somethingshown=1;
@@ -2993,22 +3021,22 @@ else
dolibarr_print_error($db);
}
}
-
+
print '';
-
+
print ' ';
-
+
// List of actions on element
include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php');
$formactions=new FormActions($db);
$somethingshown=$formactions->showactions($fac,'invoice',$socid);
-
+
print '
';
}
/*
- * Affiche formulaire mail
- */
+ * Affiche formulaire mail
+ */
if ($_GET['action'] == 'presend')
{
$ref = sanitize_string($fac->ref);
@@ -3069,7 +3097,7 @@ else
$formmail->clear_attached_files();
$formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
}
-
+
$formmail->show_form();
print ' ';
@@ -3132,7 +3160,7 @@ else
$formmail->clear_attached_files();
$formmail->add_attached_files($file,$ref.'.pdf','application/pdf');
}
-
+
$formmail->show_form();
print ' ';
@@ -3179,9 +3207,9 @@ else
if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
$sql.= ' WHERE f.fk_soc = s.rowid';
if (!$user->rights->societe->client->voir && !$socid) //restriction
- {
- $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
- }
+ {
+ $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
+ }
if ($socid) $sql .= ' AND s.rowid = '.$socid;
if ($month > 0) $sql .= ' AND date_format(f.datef, \'%m\') = '.$month;
if ($_GET['filtre'])
@@ -3287,17 +3315,17 @@ else
print ' ';
print '';
-
+
$facturestatic->id=$objp->facid;
$facturestatic->ref=$objp->facnumber;
$facturestatic->type=$objp->type;
-
+
print '';
print '';
print $facturestatic->getNomUrl(1);
print $objp->increment;
print ' ';
- if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am)
+ if ($objp->datelimite < (time() - $conf->facture->client->warning_delay) && ! $objp->paye && $objp->fk_statut == 1 && ! $objp->am)
{
print '';
print img_warning($langs->trans('Late'));
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index c733a2eca96..debe146ba50 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -57,7 +57,10 @@ class Facture extends CommonObject
var $client;
var $number;
var $author;
+ //! Invoice date
var $date;
+ var $date_creation;
+ var $date_validation;
var $ref;
var $ref_client;
//! 0=Facture normale, 1=Facture remplacement, 2=Facture avoir, 3=Facture récurrente
@@ -423,11 +426,13 @@ class Facture extends CommonObject
dolibarr_syslog("Facture::Fetch rowid=".$rowid.", societe_id=".$societe_id, LOG_DEBUG);
$sql = 'SELECT f.facnumber,f.ref_client,f.type,f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise';
- $sql.= ','.$this->db->pdate('f.datef').' as df, f.fk_projet';
+ $sql.= ','.$this->db->pdate('f.datef').' as df';
$sql.= ','.$this->db->pdate('f.date_lim_reglement').' as dlr';
+ $sql.= ','.$this->db->pdate('f.datec').' as datec';
+ $sql.= ','.$this->db->pdate('f.date_valid').' as datev';
$sql.= ', f.note, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.model_pdf';
$sql.= ', f.fk_facture_source';
- $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement';
+ $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture';
$sql.= ', cf.fk_commande';
@@ -453,6 +458,8 @@ class Facture extends CommonObject
$this->ref_client = $obj->ref_client;
$this->type = $obj->type;
$this->date = $obj->df;
+ $this->date_creation = $obj->datec;
+ $this->date_validation = $obj->datev;
$this->amount = $obj->amount;
$this->remise_percent = $obj->remise_percent;
$this->remise_absolue = $obj->remise_absolue;
@@ -995,11 +1002,11 @@ class Facture extends CommonObject
}
/**
- * \brief Tag la facture comme validée + appel trigger BILL_VALIDATE
- * \param user Utilisateur qui valide la facture
- * \param soc Ne sert plus \\TODO A virer
- * \param force_number Référence à forcer de la facture
- * \return int <0 si ko, >0 si ok
+ * \brief Tag la facture comme validée + appel trigger BILL_VALIDATE
+ * \param user Utilisateur qui valide la facture
+ * \param soc Ne sert plus. \\TODO A virer
+ * \param force_number Référence à forcer de la facture
+ * \return int <0 si ko, >0 si ok
*/
function set_valid($user, $soc='', $force_number='')
{
diff --git a/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php b/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
index cee14ce67e5..67f9cf0edf6 100644
--- a/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
+++ b/htdocs/fourn/commande/modules/mod_commande_fournisseur_orchidee.php
@@ -111,7 +111,7 @@ class mod_commande_fournisseur_orchidee extends ModeleNumRefSuppliersOrders
return 0;
}
- $numFinal=get_next_value($db,$mask,'commande_fournisseur','ref','',$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'commande_fournisseur','ref','',$objsoc->code_client,$commande->date_commande);
return $numFinal;
}
diff --git a/htdocs/includes/modules/commande/mod_commande_marbre.php b/htdocs/includes/modules/commande/mod_commande_marbre.php
index 894fc73090c..b2b474322e2 100644
--- a/htdocs/includes/modules/commande/mod_commande_marbre.php
+++ b/htdocs/includes/modules/commande/mod_commande_marbre.php
@@ -88,9 +88,9 @@ class mod_commande_marbre extends ModeleNumRefCommandes
* \param commande Object order
* \return string Value if OK, 0 if KO
*/
- function getNextValue($objsoc=0,$commande)
+ function getNextValue($objsoc,$commande)
{
- global $db;
+ global $db;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
$coyymm='';
@@ -129,22 +129,25 @@ class mod_commande_marbre extends ModeleNumRefCommandes
{
$max=0;
}
- $yymm = strftime("%y%m",time());
+ //$date=time();
+ $date=$commande->date;
+ $yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
- dolibarr_syslog("mod_commande_marbre::getNextValue return ".$this->prefix."$yymm-$num");
- return $this->prefix."$yymm-$num";
+ dolibarr_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
+ return $this->prefix.$yymm."-".$num;
}
- /** \brief Renvoie la référence de commande suivante non utilisée
- * \param objsoc Objet société
- * \return string Texte descripif
- */
- function commande_get_num($objsoc=0)
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function commande_get_num($objsoc,$objforref)
{
- return $this->getNextValue($objsoc);
+ return $this->getNextValue($objsoc,$objforref);
}
+
}
-
?>
diff --git a/htdocs/includes/modules/commande/mod_commande_opale.php b/htdocs/includes/modules/commande/mod_commande_opale.php
index 75eba5b1686..f37b2f10662 100644
--- a/htdocs/includes/modules/commande/mod_commande_opale.php
+++ b/htdocs/includes/modules/commande/mod_commande_opale.php
@@ -64,11 +64,13 @@ class mod_commande_opale extends ModeleNumRefCommandes
}
- /** \brief Renvoi prochaine valeur attribuée
- * \return string Valeur
- */
- function getNextValue()
- {
+ /** \brief Return next value
+ * \param objsoc Objet third party
+ * \param commande Object order
+ * \return string Value if OK, 0 if KO
+ */
+ function getNextValue($objsoc,$commande)
+ {
global $db;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
@@ -90,20 +92,24 @@ class mod_commande_opale extends ModeleNumRefCommandes
{
$max=0;
}
- $yy = strftime("%y",time());
+ //$date=time();
+ $date=$commande->date;
+ $yy = strftime("%y",$date);
$hex = strtoupper(dechex($max+1));
$ref = substr("000000".($hex),-6);
return 'COM-'.substr($ref,0,3)."-".substr($ref,3,3);
}
- /** \brief Renvoie la référence de commande suivante non utilisée
- * \param objsoc Objet société
- * \return string Texte descripif
- */
- function commande_get_num($objsoc=0)
- {
- return $this->getNextValue();
- }
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function commande_get_num($objsoc,$objforref)
+ {
+ return $this->getNextValue($objsoc,$objforref);
+ }
+
}
?>
diff --git a/htdocs/includes/modules/commande/mod_commande_saphir.php b/htdocs/includes/modules/commande/mod_commande_saphir.php
index fa87ac14a1d..a8b53da7559 100644
--- a/htdocs/includes/modules/commande/mod_commande_saphir.php
+++ b/htdocs/includes/modules/commande/mod_commande_saphir.php
@@ -96,7 +96,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes
* \param commande Object order
* \return string Value if OK, 0 if KO
*/
- function getNextValue($objsoc=0,$commande)
+ function getNextValue($objsoc,$commande)
{
global $db,$conf;
@@ -111,22 +111,22 @@ class mod_commande_saphir extends ModeleNumRefCommandes
return 0;
}
- $numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'commande','ref','',$objsoc->code_client,$commande->date);
return $numFinal;
}
- /** \brief Renvoie la référence de commande suivante non utilisée
- * \param objsoc Objet société
- * \param commande Objet commande
- * \return string Texte descripif
- */
- function commande_get_num($objsoc=0,$commande)
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function commande_get_num($objsoc,$objforref)
{
- return $this->getNextValue($objsoc,$commande);
+ return $this->getNextValue($objsoc,$objforref);
}
-
+
}
?>
\ No newline at end of file
diff --git a/htdocs/includes/modules/facture/mercure/mercure.modules.php b/htdocs/includes/modules/facture/mercure/mercure.modules.php
index 0b3ef1943ef..d102a459d59 100644
--- a/htdocs/includes/modules/facture/mercure/mercure.modules.php
+++ b/htdocs/includes/modules/facture/mercure/mercure.modules.php
@@ -121,21 +121,21 @@ class mod_facture_mercure extends ModeleNumRefFactures
if ($facture->type == 2) $where.= " AND type = 2";
else $where.=" AND type != 2";
- $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc->code_client,$facture->date);
return $numFinal;
}
- /** \brief Renvoie la reference de commande suivante non utilisee
- * \param objsoc Objet societe
- * \param facture Objet facture
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0,$facture)
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
{
- return $this->getNextValue($objsoc,$facture);
+ return $this->getNextValue($objsoc,$objforref);
}
-
+
}
?>
\ No newline at end of file
diff --git a/htdocs/includes/modules/facture/terre/terre.modules.php b/htdocs/includes/modules/facture/terre/terre.modules.php
index d282a452fde..705603a253a 100644
--- a/htdocs/includes/modules/facture/terre/terre.modules.php
+++ b/htdocs/includes/modules/facture/terre/terre.modules.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2005-2008 Laurent Destailleur
* Copyright (C) 2005 Regis Houssin
*
* This program is free software; you can redistribute it and/or modify
@@ -16,16 +16,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
*/
/**
\file htdocs/includes/modules/facture/terre/terre.modules.php
\ingroup facture
\brief Fichier contenant la classe du modèle de numérotation de référence de facture Terre
- \version $Revision$
+ \version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/facture/modules_facture.php");
@@ -145,9 +142,9 @@ class mod_facture_terre extends ModeleNumRefFactures
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=8;
- $sql = "SELECT MAX(0+SUBSTRING(facnumber,$posindice))";
+ $sql = "SELECT MAX(0+SUBSTRING(facnumber,".$posindice."))";
$sql.= " FROM ".MAIN_DB_PREFIX."facture";
- $sql.= " WHERE facnumber like '${fayymm}%'";
+ $sql.= " WHERE facnumber like '".$fayymm."%'";
$resql=$db->query($sql);
if ($resql)
{
@@ -159,21 +156,24 @@ class mod_facture_terre extends ModeleNumRefFactures
{
$max=0;
}
- $yymm = strftime("%y%m",time());
+
+ //$date=time();
+ $date=$facture->date;
+ $yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1);
- dolibarr_syslog("mod_facture_terre::getNextValue return ".$prefix."$yymm-$num");
- return $prefix."$yymm-$num";
+ dolibarr_syslog("mod_facture_terre::getNextValue return ".$prefix.$yymm."-".$num);
+ return $prefix.$yymm."-".$num;
}
- /** \brief Renvoie la référence de facture suivante non utilisée
- * \param objsoc Objet société
- * \param facture Objet facture
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0,$facture)
- {
- return $this->getNextValue($objsoc,$facture);
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
+ {
+ return $this->getNextValue($objsoc,$objforref);
}
}
diff --git a/htdocs/includes/modules/fichinter/mod_arctic.php b/htdocs/includes/modules/fichinter/mod_arctic.php
index c2c95efdf08..09530ed51ca 100644
--- a/htdocs/includes/modules/fichinter/mod_arctic.php
+++ b/htdocs/includes/modules/fichinter/mod_arctic.php
@@ -116,20 +116,20 @@ class mod_arctic extends ModeleNumRefFicheinter
return 0;
}
- $numFinal=get_next_value($db,$mask,'fichinter','ref','',$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'fichinter','ref','',$objsoc->code_client,$ficheinter->date);
return $numFinal;
}
- /** \brief Renvoie la référence de fichinter suivante non utilisée
- * \param objsoc Objet société
- * \param fichinter Objet fichinter
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0,$ficheinter='')
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
{
- return $this->getNextValue($objsoc,$ficheinter);
+ return $this->getNextValue($objsoc,$objforref);
}
}
diff --git a/htdocs/includes/modules/fichinter/mod_pacific.php b/htdocs/includes/modules/fichinter/mod_pacific.php
index a398b15343c..e20da85a6ec 100644
--- a/htdocs/includes/modules/fichinter/mod_pacific.php
+++ b/htdocs/includes/modules/fichinter/mod_pacific.php
@@ -16,16 +16,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
*/
/**
\file htdocs/includes/modules/fichinter/mod_pacific.php
- \ingroup fiche intervention
- \brief Fichier contenant la classe du modèle de numérotation de référence de fiche intervention Pacific
- \version $Revision$
+ \ingroup fiche intervention
+ \brief Fichier contenant la classe du modèle de numérotation de référence de fiche intervention Pacific
+ \version $Id$
*/
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/modules_fichinter.php");
@@ -100,11 +97,13 @@ class mod_pacific extends ModeleNumRefFicheinter
}
}
- /** \brief Renvoi prochaine valeur attribuée
- * \return string Valeur
- */
- function getNextValue()
- {
+ /** \brief Renvoi prochaine valeur attribuée
+ * \param objsoc Objet société
+ * \param ficheinter Object ficheinter
+ * \return string Valeur
+ */
+ function getNextValue($objsoc=0,$ficheinter='')
+ {
global $db;
// D'abord on récupère la valeur max (réponse immédiate car champ indéxé)
@@ -123,9 +122,9 @@ class mod_pacific extends ModeleNumRefFicheinter
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=8;
- $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
+ $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice."))";
$sql.= " FROM ".MAIN_DB_PREFIX."fichinter";
- $sql.= " WHERE ref like '${fayymm}%'";
+ $sql.= " WHERE ref like '".$fayymm."%'";
$resql=$db->query($sql);
if ($resql)
{
@@ -137,19 +136,21 @@ class mod_pacific extends ModeleNumRefFicheinter
{
$max=0;
}
- $yymm = strftime("%y%m",time());
+ //$yymm = strftime("%y%m",time());
+ $yymm = strftime("%y%m",$ficheinter->date);
$num = sprintf("%04s",$max+1);
- return $this->prefix."$yymm-$num";
+ return $this->prefix.$yymm."-".$num;
}
- /** \brief Renvoie la référence de fiche d'intervention suivante non utilisée
- * \param objsoc Objet société
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0)
- {
- return $this->getNextValue();
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
+ {
+ return $this->getNextValue($objsoc,$objforref);
}
}
diff --git a/htdocs/includes/modules/propale/mod_propale_marbre.php b/htdocs/includes/modules/propale/mod_propale_marbre.php
index 5257b18538b..dcbf4505d19 100644
--- a/htdocs/includes/modules/propale/mod_propale_marbre.php
+++ b/htdocs/includes/modules/propale/mod_propale_marbre.php
@@ -1,5 +1,5 @@
+/* Copyright (C) 2005-2008 Laurent Destailleur
* Copyright (C) 2005 Regis Houssin
*
* This program is free software; you can redistribute it and/or modify
@@ -85,11 +85,12 @@ class mod_propale_marbre extends ModeleNumRefPropales
}
}
- /** \brief Renvoi prochaine valeur attribuée
- * \param objsoc Objet société
- * \return string Valeur
- */
- function getNextValue($objsoc=0)
+ /** \brief Return next value
+ * \param objsoc Object third party
+ * \param propal Object commercial proposal
+ * \return string Valeur
+ */
+ function getNextValue($objsoc,$propal)
{
global $db;
@@ -114,9 +115,9 @@ class mod_propale_marbre extends ModeleNumRefPropales
{
// Recherche rapide car restreint par un like sur champ indexé
$posindice=8;
- $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
+ $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice."))";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
- $sql.= " WHERE ref like '${pryymm}%'";
+ $sql.= " WHERE ref like '".$pryymm."%'";
$resql=$db->query($sql);
if ($resql)
{
@@ -128,20 +129,22 @@ class mod_propale_marbre extends ModeleNumRefPropales
{
$max=0;
}
- $yymm = strftime("%y%m",time());
+ //$yymm = strftime("%y%m",time());
+ $yymm = strftime("%y%m",$propal->date);
$num = sprintf("%04s",$max+1);
- dolibarr_syslog("mod_propale_marbre::getNextValue return ".$this->prefix."$yymm-$num");
- return $this->prefix."$yymm-$num";
+ dolibarr_syslog("mod_propale_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
+ return $this->prefix.$yymm."-".$num;
}
- /** \brief Renvoie la référence de propale suivante non utilisée
- * \param objsoc Objet société
- * \return string Texte descripif
- */
- function getNumRef($objsoc=0)
- {
- return $this->getNextValue();
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
+ {
+ return $this->getNextValue($objsoc,$objforref);
}
}
diff --git a/htdocs/includes/modules/propale/mod_propale_saphir.php b/htdocs/includes/modules/propale/mod_propale_saphir.php
index 46fcea46df4..177786ce7c0 100644
--- a/htdocs/includes/modules/propale/mod_propale_saphir.php
+++ b/htdocs/includes/modules/propale/mod_propale_saphir.php
@@ -96,7 +96,7 @@ class mod_propale_saphir extends ModeleNumRefPropales
* \param propal Object commercial proposal
* \return string Value if OK, 0 if KO
*/
- function getNextValue($objsoc,$propal='')
+ function getNextValue($objsoc,$propal)
{
global $db,$conf;
@@ -111,7 +111,7 @@ class mod_propale_saphir extends ModeleNumRefPropales
return 0;
}
- $numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'propal','ref','',$objsoc->code_client,$propal->date);
return $numFinal;
}
diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php
index f4adf048590..bbde34f608b 100644
--- a/htdocs/lib/functions2.lib.php
+++ b/htdocs/lib/functions2.lib.php
@@ -32,10 +32,16 @@
* @param $mask
* @param unknown_type $table
* @param unknown_type $field
+ * @param unknown_type $where
+ * @param unknown_type $valueforccc
+ * @param unknown_type $date
* @return string New value
*/
-function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='')
+function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date='')
{
+ // Clean parameters
+ if ($date == '') $date=time();
+
// Extract value for mask counter, mask raz and mask offset
if (! eregi('\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}',$mask,$reg)) return 'ErrorBadMask';
$masktri=$reg[1].$reg[2].$reg[3];
@@ -92,10 +98,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='')
$monthcomp=$maskraz;
$yearoffset=0;
$yearcomp=0;
- if (date("m") < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
- if (strlen($reg[2]) == 4) $yearcomp=sprintf("%04d",date("Y")+$yearoffset);
- if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y")+$yearoffset);
- if (strlen($reg[2]) == 1) $yearcomp=substr(date("y"),2,1)+$yearoffset;
+ if (date("m",$date) < $maskraz) { $yearoffset=-1; } // If current month lower that month of return to zero, year is previous year
+ if (strlen($reg[2]) == 4) $yearcomp=sprintf("%04d",date("Y",$date)+$yearoffset);
+ if (strlen($reg[2]) == 2) $yearcomp=sprintf("%02d",date("y",$date)+$yearoffset);
+ if (strlen($reg[2]) == 1) $yearcomp=substr(date("y",$date),2,1)+$yearoffset;
$sqlwhere='';
$sqlwhere.='SUBSTRING('.$field.', '.(strlen($reg[1])+1).', '.strlen($reg[2]).') >= '.$yearcomp;
@@ -191,11 +197,11 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='')
$numFinal = $mask;
// We replace special codes except refclient
- $numFinal = str_replace('{yyyy}',date("Y"),$numFinal);
- $numFinal = str_replace('{yy}',date("y"),$numFinal);
- $numFinal = str_replace('{y}' ,substr(date("y"),2,1),$numFinal);
- $numFinal = str_replace('{mm}',date("m"),$numFinal);
- $numFinal = str_replace('{dd}',date("d"),$numFinal);
+ $numFinal = str_replace('{yyyy}',date("Y",$date),$numFinal);
+ $numFinal = str_replace('{yy}',date("y",$date),$numFinal);
+ $numFinal = str_replace('{y}' ,substr(date("y",$date),2,1),$numFinal);
+ $numFinal = str_replace('{mm}',date("m",$date),$numFinal);
+ $numFinal = str_replace('{dd}',date("d",$date),$numFinal);
if ($maskclientcode) $numFinal = str_replace(('{'.$maskclientcode.'}'),$clientcode,$numFinal);
// Now we replace the counter
diff --git a/htdocs/lib/propal.lib.php b/htdocs/lib/propal.lib.php
index de5fc8c7362..85c6b20ec06 100644
--- a/htdocs/lib/propal.lib.php
+++ b/htdocs/lib/propal.lib.php
@@ -15,16 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
- *
- * $Id$
- * $Source$
*/
/**
\file htdocs/lib/propal.lib.php
\brief Ensemble de fonctions de base pour le module propal
\ingroup propal
- \version $Revision$
+ \version $Id$
Ensemble de fonctions de base de dolibarr sous forme d'include
*/
diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php
index 77dae1ff770..ddbb63c282d 100644
--- a/htdocs/livraison/livraison.class.php
+++ b/htdocs/livraison/livraison.class.php
@@ -47,6 +47,11 @@ class Livraison extends CommonObject
var $origin_id;
var $socid;
+ var $date_livraison;
+ var $date_creation;
+ var $date_valid;
+
+
/**
* Initialisation
*
@@ -241,6 +246,7 @@ class Livraison extends CommonObject
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
+ $this->date_livraison = $obj->date_livraison;
$this->date_creation = $obj->date_creation;
$this->date_valid = $obj->date_valid;
$this->ref = $obj->ref;
@@ -251,7 +257,6 @@ class Livraison extends CommonObject
$this->expedition_id = $obj->fk_expedition;
$this->user_author_id = $obj->fk_user_author;
$this->user_valid_id = $obj->fk_user_valid;
- $this->date_livraison = $obj->date_livraison;
$this->adresse_livraison_id = $obj->fk_adresse_livraison;
$this->note = $obj->note;
$this->note_public = $obj->note_public;
@@ -695,7 +700,58 @@ class Livraison extends CommonObject
if ($statut==1) return img_picto($langs->trans('StatusSendingValidated'),'statut4').' '.$langs->trans('StatusSendingValidated');
}
}
+
+ /**
+ * \brief Initialise object with default value to be used as example
+ */
+ function initAsSpecimen()
+ {
+ global $user,$langs;
+
+ // Charge tableau des id de soci�t� socids
+ $socids = array();
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num_socs = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num_socs)
+ {
+ $i++;
+
+ $row = $this->db->fetch_row($resql);
+ $socids[$i] = $row[0];
+ }
+ }
+
+ // Charge tableau des produits prodids
+ $prodids = array();
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1";
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $num_prods = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num_prods)
+ {
+ $i++;
+ $row = $this->db->fetch_row($resql);
+ $prodids[$i] = $row[0];
+ }
+ }
+
+ // Initialise parametres
+ $this->id=0;
+ $this->ref = 'SPECIMEN';
+ $this->specimen=1;
+ $socid = rand(1, $num_socs);
+ $this->socid = $socids[$socid];
+ $this->date_livraison = time();
+ $this->note_public='SPECIMEN';
+ }
+
}
diff --git a/htdocs/livraison/mods/mod_livraison_jade.php b/htdocs/livraison/mods/mod_livraison_jade.php
index a8cc8bf7b4c..96f2e90179a 100644
--- a/htdocs/livraison/mods/mod_livraison_jade.php
+++ b/htdocs/livraison/mods/mod_livraison_jade.php
@@ -57,10 +57,12 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
return "BL0600001";
}
- /** \brief Renvoi prochaine valeur attribuée
- * \return string Valeur
- */
- function getNextValue()
+ /** \brief Return next value
+ * \param objsoc Object third party
+ * \param livraison Object delivery
+ * \return string Value if OK, 0 if KO
+ */
+ function getNextValue($objsoc=0,$livraison='')
{
global $db;
@@ -82,7 +84,7 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
$posindice=5;
$sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))";
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
- $sql.= " WHERE ref like '${blyy}%'";
+ $sql.= " WHERE ref like '".$blyy."%'";
$resql=$db->query($sql);
if ($resql)
{
@@ -94,7 +96,9 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
{
$max=0;
}
- $yy = strftime("%y",time());
+ //$date=time();
+ $date=$livraison->date_livraison;
+ $yy = strftime("%y",$date);
$num = sprintf("%05s",$max+1);
return "BL$yy$num";
@@ -103,11 +107,12 @@ class mod_livraison_jade extends ModeleNumRefDeliveryOrder
/** \brief Renvoie la référence de commande suivante non utilisée
* \param objsoc Objet société
+ * \param livraison Objet livraison
* \return string Texte descripif
*/
- function livraison_get_num($objsoc=0)
+ function livraison_get_num($objsoc=0,$livraison='')
{
- return $this->getNextValue();
+ return $this->getNextValue($objsoc,$livraison);
}
}
?>
diff --git a/htdocs/livraison/mods/mod_livraison_saphir.php b/htdocs/livraison/mods/mod_livraison_saphir.php
index 655646319ce..068c5f3a676 100644
--- a/htdocs/livraison/mods/mod_livraison_saphir.php
+++ b/htdocs/livraison/mods/mod_livraison_saphir.php
@@ -92,7 +92,7 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
/** \brief Return next value
* \param objsoc Object third party
- * \param livraison Object proposal
+ * \param livraison Object delivery
* \return string Value if OK, 0 if KO
*/
function getNextValue($objsoc=0,$livraison='')
@@ -110,15 +110,26 @@ class mod_livraison_saphir extends ModeleNumRefDeliveryOrder
return 0;
}
- $numFinal=get_next_value($db,$mask,'livraison','ref','',$objsoc->code_client);
+ $numFinal=get_next_value($db,$mask,'livraison','ref','',$objsoc->code_client,$livraison->date_livraison);
return $numFinal;
}
-
+
- /** \brief Renvoie la référence de commande suivante non utilisée
+ /** \brief Return next free value
+ * \param objsoc Object third party
+ * \param objforref Object for number to search
+ * \return string Next free value
+ */
+ function getNumRef($objsoc,$objforref)
+ {
+ return $this->getNextValue($objsoc,$objforref);
+ }
+
+
+ /** \brief Renvoie la référence de commande suivante non utilisée
* \param objsoc Objet société
- * \param commande Objet commande
+ * \param livraison Objet livraison
* \return string Texte descripif
*/
function livraison_get_num($objsoc=0,$livraison='')
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index aa7df011e89..5b2b6b0befe 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -61,7 +61,10 @@ class Propal extends CommonObject
var $ref;
var $ref_client;
var $statut; // 0, 1, 2, 3, 4
- var $datep;
+ var $date; // Date of proposal
+ var $datep; // Duplicate with date
+ var $date_livraison;
+
var $fin_validite;
var $price; // Total HT
var $tva; // Total TVA
@@ -75,7 +78,6 @@ class Propal extends CommonObject
var $remise_absolue;
var $note;
var $note_public;
- var $date_livraison;
var $adresse_livraison_id;
var $adresse;
@@ -685,9 +687,9 @@ class Propal extends CommonObject
$this->id = $rowid;
+ $this->date = $obj->dp;
$this->datep = $obj->dp;
$this->fin_validite = $obj->dfv;
- $this->date = $obj->dp;
$this->ref = $obj->ref;
$this->ref_client = $obj->ref_client;
$this->remise = $obj->remise;
@@ -1693,8 +1695,7 @@ class Propal extends CommonObject
/**
- * \brief Initialise la propale avec valeurs fictives al�atoire
- * Sert � g�n�rer une facture pour l'aperu des mod�les ou demo
+ * \brief Initialise object with default value to be used as example
*/
function initAsSpecimen()
{