diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 0ad3f1f0677..f390020fedb 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -159,7 +159,7 @@ if ($_POST["action"] == 'set_use_customer_contact_as_recipient') /* - * Affichage page + * View */ llxHeader(); @@ -225,7 +225,8 @@ if ($handle) print ''; $commande=new Commande($db); - + $commande->initAsSpecimen(); + // Info $htmltooltip=''; $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index a20a939f14e..17c2c174676 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -281,7 +281,8 @@ while (($file = readdir($handle))!==false) print ''; $facture=new Facture($db); - + $facture->initAsSpecimen(); + // Example for standard invoice $htmltooltip=''; $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; diff --git a/htdocs/admin/livraison.php b/htdocs/admin/livraison.php index 5fd74a080f6..33f6392ecee 100644 --- a/htdocs/admin/livraison.php +++ b/htdocs/admin/livraison.php @@ -226,12 +226,13 @@ if ($handle) print ''; $livraison=new Livraison($db); + $livraison->initAsSpecimen(); // Info $htmltooltip=''; $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; $facture->type=0; - $nextval=$module->getNextValue($mysoc,$propale); + $nextval=$module->getNextValue($mysoc,$livraison); if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval { $htmltooltip.=''.$langs->trans("NextValue").': '; diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php index 7df46ea9546..8cc3bac4e81 100644 --- a/htdocs/admin/propale.php +++ b/htdocs/admin/propale.php @@ -5,7 +5,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2007 Regis Houssin - * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2008 Raphael Bertrand (Resultic) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -195,7 +195,7 @@ $linkback=''.$langs->trans("BackToM print_fiche_titre($langs->trans("PropalSetup"),$linkback,'setup'); /* - * Module num�rotation + * Module numerotation */ print "
"; print_titre($langs->trans("ProposalsNumberingModules")); @@ -249,6 +249,7 @@ if ($handle) print ''; $propale=new Propal($db); + $propale->initAsSpecimen(); // Info $htmltooltip=''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 7e9df565fb2..3192267797e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -22,11 +22,11 @@ */ /** - \file htdocs/compta/facture.php - \ingroup facture - \brief Page de création/visu facture - \version $Id$ -*/ + \file htdocs/compta/facture.php + \ingroup facture + \brief Page de création/visu facture + \version $Id$ + */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); @@ -42,7 +42,7 @@ if ($conf->contrat->enabled) require_once(DOL_DOCUMENT_ROOT.'/contrat/contrat.c if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); if (! $user->rights->facture->lire) - accessforbidden(); +accessforbidden(); $langs->load('bills'); $langs->load('companies'); @@ -91,7 +91,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') * Supprime une ligne produit AVEC ou SANS confirmation */ if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) - || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) +|| ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) { if ($user->rights->facture->creer) { @@ -105,7 +105,7 @@ if (($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'ye $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - + $result=facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); if ($result > 0) { @@ -195,9 +195,9 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->facture->creer) // POST[remise_id] ou POST[remise_id_for_payment] if (! empty($_POST["remise_id"])) { - $fac = new Facture($db); - $fac->id=$_GET['facid']; - $ret=$fac->fetch($_GET['facid']); + $fac = new Facture($db); + $fac->id=$_GET['facid']; + $ret=$fac->fetch($_GET['facid']); if ($ret > 0) { $result=$fac->insert_discount($_POST["remise_id"]); @@ -216,7 +216,7 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->facture->creer) require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); $discount = new DiscountAbsolute($db); $discount->fetch($_POST["remise_id_for_payment"]); - + $result=$discount->link_to_invoice(0,$_GET['facid']); if ($result < 0) { @@ -258,47 +258,47 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user-> // Repasse la facture en mode brouillon if ($_GET['action'] == 'modif' && $user->rights->facture->modifier && $conf->global->FACTURE_ENABLE_EDITDELETE) { - $fac = new Facture($db); - $fac->fetch($_GET['facid']); + $fac = new Facture($db); + $fac->fetch($_GET['facid']); - // On vérifie si la facture a des paiements - $sql = 'SELECT pf.amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; - $sql.= ' WHERE pf.fk_facture = '.$fac->id; - - $result = $db->query($sql); - - if ($result) - { - $i = 0; - $num = $db->num_rows($result); - - while ($i < $num) + // On vérifie si la facture a des paiements + $sql = 'SELECT pf.amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; + $sql.= ' WHERE pf.fk_facture = '.$fac->id; + + $result = $db->query($sql); + + if ($result) { + $i = 0; + $num = $db->num_rows($result); + + while ($i < $num) + { $objp = $db->fetch_object($result); $totalpaye += $objp->amount; $i++; + } + } + + $resteapayer = $fac->total_ttc - $totalpaye; + + // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées + $ventilExportCompta = $fac->getVentilExportCompta(); + + // On vérifie si aucun paiement n'a été effectué + if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0) + { + $fac->set_draft($user); } - } - - $resteapayer = $fac->total_ttc - $totalpaye; - - // On vérifie si les lignes de factures ont été exportées en compta et/ou ventilées - $ventilExportCompta = $fac->getVentilExportCompta(); - - // On vérifie si aucun paiement n'a été effectué - if ($resteapayer == $fac->total_ttc && $fac->paye == 0 && $ventilExportCompta == 0) - { - $fac->set_draft($user); - } } // Classe à "payée" if ($_POST['action'] == 'confirm_payed' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement) { - $fac = new Facture($db); - $fac->fetch($_GET['facid']); - $result = $fac->set_payed($user); + $fac = new Facture($db); + $fac->fetch($_GET['facid']); + $result = $fac->set_payed($user); } // Classe à "payée partiellement" if ($_POST['action'] == 'confirm_payed_partially' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement) @@ -337,7 +337,7 @@ if ($_POST['action'] == 'confirm_canceled' && $_POST['confirm'] == 'yes') if ($_POST['action'] == 'confirm_converttoreduc' && $_POST['confirm'] == 'yes' && $user->rights->facture->creer) { $db->begin(); - + $fac = new Facture($db); $fac->fetch($_GET['facid']); $fac->fetch_client(); @@ -354,7 +354,7 @@ if ($_POST['action'] == 'confirm_converttoreduc' && $_POST['confirm'] == 'yes' & $amount_ttc[$ligne->tva_tx]+=$ligne->total_ttc; $i++; } - + // Insère une remise par famille de taux tva $discount = new DiscountAbsolute($db); $discount->desc='(CREDIT_NOTE)'; @@ -371,13 +371,13 @@ if ($_POST['action'] == 'confirm_converttoreduc' && $_POST['confirm'] == 'yes' & $discount->tva_tx=abs($tva_tx); $result=$discount->create($user); - if ($result < 0) + if ($result < 0) { $error++; break; } } - + if (! $error) { // Classe facture @@ -404,7 +404,7 @@ if ($_POST['action'] == 'confirm_converttoreduc' && $_POST['confirm'] == 'yes' & /* - * Insertion facture + * Insert invoice */ if ($_POST['action'] == 'add' && $user->rights->facture->creer) { @@ -417,10 +417,22 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) // Facture remplacement if ($_POST['type'] == 1) { - if ($_POST['fac_replacement'] > 0) + $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + if (empty($datefacture)) + { + $error=1; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; + } + + if (! $_POST['fac_replacement'] > 0) + { + $error=1; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).'
'; + } + + if (! $error) { // Si facture remplacement - $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $result=$facture->fetch($_POST['fac_replacement']); @@ -441,18 +453,26 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $facid=$facture->create_clone($user); } - else - { - $error=1; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).'
'; - } } // Facture avoir if ($_POST['type'] == 2) { - if ($_POST['fac_avoir'] > 0) + if (! $_POST['fac_avoir'] > 0) { + $error=1; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'
'; + } + + $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + if (empty($datefacture)) + { + $error=1; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; + } + + if (! $error) + { // Si facture avoir $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -477,11 +497,6 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $facid = $facture->create($user); } - else - { - $error=1; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).'
'; - } } if ($_POST['type'] == 0 && $_POST['fac_rec'] > 0) @@ -507,64 +522,72 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) if ($_POST['type'] == 0 && $_POST['fac_rec'] <= 0) { - // Si facture standard $datefacture = dolibarr_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - - $facture->socid = $_POST['socid']; - $facture->type = $_POST['type']; - $facture->number = $_POST['facnumber']; - $facture->date = $datefacture; - $facture->note_public = trim($_POST['note_public']); - $facture->note = trim($_POST['note']); - $facture->ref_client = $_POST['ref_client']; - $facture->modelpdf = $_POST['model']; - $facture->projetid = $_POST['projetid']; - $facture->cond_reglement_id = $_POST['cond_reglement_id']; - $facture->mode_reglement_id = $_POST['mode_reglement_id']; - $facture->amount = $_POST['amount']; - $facture->remise_absolue = $_POST['remise_absolue']; - $facture->remise_percent = $_POST['remise_percent']; - - if (! $_POST['propalid'] && ! $_POST['commandeid'] && ! $_POST['contratid']) + if (empty($datefacture)) { - for ($i = 1; $i <= $NBLINES; $i++) - { - if ($_POST['idprod'.$i]) - { - $startday=''; - $endday=''; - if ($_POST['date_start'.$i.'year'] && $_POST['date_start'.$i.'month'] && $_POST['date_start'.$i.'day']) { - $startday=$_POST['date_start'.$i.'year'].'-'.$_POST['date_start'.$i.'month'].'-'.$_POST['date_start'.$i.'day']; - } - if ($_POST['date_end'.$i.'year'] && $_POST['date_end'.$i.'month'] && $_POST['date_end'.$i.'day']) { - $endday=$_POST['date_end'.$i.'year'].'-'.$_POST['date_end'.$i.'month'].'-'.$_POST['date_end'.$i.'day']; - } - $facture->add_product($_POST['idprod'.$i],$_POST['qty'.$i],$_POST['remise_percent'.$i],$startday,$endday); - } - } - - $facid = $facture->create($user); + $error=1; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).'
'; } - else - { - /* - * Si creation depuis propale - */ - if ($_POST['propalid']) + + if (! $error) + { + // Si facture standard + + $facture->socid = $_POST['socid']; + $facture->type = $_POST['type']; + $facture->number = $_POST['facnumber']; + $facture->date = $datefacture; + $facture->note_public = trim($_POST['note_public']); + $facture->note = trim($_POST['note']); + $facture->ref_client = $_POST['ref_client']; + $facture->modelpdf = $_POST['model']; + $facture->projetid = $_POST['projetid']; + $facture->cond_reglement_id = $_POST['cond_reglement_id']; + $facture->mode_reglement_id = $_POST['mode_reglement_id']; + $facture->amount = $_POST['amount']; + $facture->remise_absolue = $_POST['remise_absolue']; + $facture->remise_percent = $_POST['remise_percent']; + + if (! $_POST['propalid'] && ! $_POST['commandeid'] && ! $_POST['contratid']) { - $facture->propalid = $_POST['propalid']; - $facid = $facture->create($user); - - if ($facid > 0) + for ($i = 1; $i <= $NBLINES; $i++) { - $prop = New Propal($db); - if ( $prop->fetch($_POST['propalid']) ) + if ($_POST['idprod'.$i]) { - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + $startday=''; + $endday=''; + if ($_POST['date_start'.$i.'year'] && $_POST['date_start'.$i.'month'] && $_POST['date_start'.$i.'day']) { + $startday=$_POST['date_start'.$i.'year'].'-'.$_POST['date_start'.$i.'month'].'-'.$_POST['date_start'.$i.'day']; + } + if ($_POST['date_end'.$i.'year'] && $_POST['date_end'.$i.'month'] && $_POST['date_end'.$i.'day']) { + $endday=$_POST['date_end'.$i.'year'].'-'.$_POST['date_end'.$i.'month'].'-'.$_POST['date_end'.$i.'day']; + } + $facture->add_product($_POST['idprod'.$i],$_POST['qty'.$i],$_POST['remise_percent'.$i],$startday,$endday); + } + } + + $facid = $facture->create($user); + } + else + { + /* + * Si creation depuis propale + */ + if ($_POST['propalid']) + { + $facture->propalid = $_POST['propalid']; + $facid = $facture->create($user); + + if ($facid > 0) + { + $prop = New Propal($db); + if ( $prop->fetch($_POST['propalid']) ) { - $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); - - $result = $facture->addline( + for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) + { + $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); + + $result = $facture->addline( $facid, $desc, $prop->lignes[$i]->subprice, @@ -572,51 +595,51 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $prop->lignes[$i]->tva_tx, $prop->lignes[$i]->fk_product, $prop->lignes[$i]->remise_percent, - '', - '', + '', + '', 0, $prop->lignes[$i]->info_bits, $prop->lignes[$i]->fk_remise_except - ); - - if ($result < 0) - { - $error++; - break; + ); + + if ($result < 0) + { + $error++; + break; + } } } + else + { + $error++; + } } else { $error++; } } - else + + /* + * Si création depuis commande + */ + if ($_POST['commandeid']) { - $error++; - } - } - - /* - * Si création depuis commande - */ - if ($_POST['commandeid']) - { - $facture->commandeid = $_POST['commandeid']; - $facid = $facture->create($user); - - if ($facid > 0) - { - $comm = New Commande($db); - if ( $comm->fetch($_POST['commandeid']) ) + $facture->commandeid = $_POST['commandeid']; + $facid = $facture->create($user); + + if ($facid > 0) { - $comm->fetch_lines(); - $lines = $comm->lignes; - for ($i = 0 ; $i < sizeof($lines) ; $i++) + $comm = New Commande($db); + if ( $comm->fetch($_POST['commandeid']) ) { - $desc=($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); - - $result = $facture->addline( + $comm->fetch_lines(); + $lines = $comm->lignes; + for ($i = 0 ; $i < sizeof($lines) ; $i++) + { + $desc=($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); + + $result = $facture->addline( $facid, $desc, $lines[$i]->subprice, @@ -624,57 +647,57 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) $lines[$i]->tva_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, - '', - '', + '', + '', 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except - ); - - if ($result < 0) - { - $error++; - break; + ); + + if ($result < 0) + { + $error++; + break; + } } } + else + { + $error++; + } } else { $error++; } } - else + + /* + * Si création depuis contrat + */ + if ($_POST['contratid']) { - $error++; - } - } - - /* - * Si création depuis contrat - */ - if ($_POST['contratid']) - { - $facture->contratid = $_POST['contratid']; - $facid = $facture->create($user); - - if ($facid > 0) - { - $contrat = New Contrat($db); - if ($contrat->fetch($_POST['contratid']) > 0) + $facture->contratid = $_POST['contratid']; + $facid = $facture->create($user); + + if ($facid > 0) { - $lines = $contrat->fetch_lignes(); - - for ($i = 0 ; $i < sizeof($lines) ; $i++) + $contrat = New Contrat($db); + if ($contrat->fetch($_POST['contratid']) > 0) { - $desc=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle); - - // Plage de dates - $date_start=$contrat->lignes[$i]->date_debut_prevue; - if ($contrat->lignes[$i]->date_debut_reel) $date_start=$contrat->lignes[$i]->date_debut_reel; - $date_end=$contrat->lignes[$i]->date_fin_prevue; - if ($contrat->lignes[$i]->date_fin_reel) $date_end=$contrat->lignes[$i]->date_fin_reel; - - $result = $facture->addline( + $lines = $contrat->fetch_lignes(); + + for ($i = 0 ; $i < sizeof($lines) ; $i++) + { + $desc=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle); + + // Plage de dates + $date_start=$contrat->lignes[$i]->date_debut_prevue; + if ($contrat->lignes[$i]->date_debut_reel) $date_start=$contrat->lignes[$i]->date_debut_reel; + $date_end=$contrat->lignes[$i]->date_fin_prevue; + if ($contrat->lignes[$i]->date_fin_reel) $date_end=$contrat->lignes[$i]->date_fin_reel; + + $result = $facture->addline( $facid, $desc, $lines[$i]->subprice, @@ -687,27 +710,27 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer) 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except - ); - - if ($result < 0) - { - $error++; - break; + ); + + if ($result < 0) + { + $error++; + break; + } } } + else + { + $error++; + } } else { $error++; } } - else - { - $error++; - } } } - } // Fin création facture, on l'affiche @@ -777,27 +800,27 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit - if ($_POST['idprod']) - { - $prod = new Product($db, $_POST['idprod']); - $prod->fetch($_POST['idprod']); + if ($_POST['idprod']) + { + $prod = new Product($db, $_POST['idprod']); + $prod->fetch($_POST['idprod']); - $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx); + $tva_tx = get_default_tva($mysoc,$fac->client,$prod->tva_tx); $tva_npr = get_default_npr($mysoc,$fac->client,$prod->tva_tx); - - // On defini prix unitaire - if ($conf->global->PRODUIT_MULTIPRICES == 1) - { - $pu_ht = $prod->multiprices[$fac->client->price_level]; - $pu_ttc = $prod->multiprices_ttc[$fac->client->price_level]; - $price_base_type = $prod->multiprices_base_type[$fac->client->price_level]; - } - else - { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; + + // On defini prix unitaire + if ($conf->global->PRODUIT_MULTIPRICES == 1) + { + $pu_ht = $prod->multiprices[$fac->client->price_level]; + $pu_ttc = $prod->multiprices_ttc[$fac->client->price_level]; + $price_base_type = $prod->multiprices_base_type[$fac->client->price_level]; + } + else + { + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; $price_base_type = $prod->price_base_type; - } + } // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). @@ -812,39 +835,39 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } - - $desc = $prod->description; + + $desc = $prod->description; $desc.= $prod->description && $_POST['np_desc'] ? "\n" : ""; - $desc.= $_POST['np_desc']; - } - else - { - $pu_ht=$_POST['pu']; - $tva_tx=eregi_replace('\*','',$_POST['tva_tx']); + $desc.= $_POST['np_desc']; + } + else + { + $pu_ht=$_POST['pu']; + $tva_tx=eregi_replace('\*','',$_POST['tva_tx']); $tva_npr=eregi('\*',$_POST['tva_tx'])?1:0; - $desc=$_POST['dp_desc']; - } - + $desc=$_POST['dp_desc']; + } + $info_bits=0; if ($tva_npr) $info_bits |= 0x01; // Insert line $result = $fac->addline( - $_POST['facid'], - $desc, - $pu_ht, - $_POST['qty'], - $tva_tx, - $_POST['idprod'], - $_POST['remise_percent'], - $date_start, - $date_end, - 0, - $info_bits, + $_POST['facid'], + $desc, + $pu_ht, + $_POST['qty'], + $tva_tx, + $_POST['idprod'], + $_POST['remise_percent'], + $date_start, + $date_end, + 0, + $info_bits, '', - $price_base_type, - $pu_ttc - ); + $price_base_type, + $pu_ttc + ); } if ($result > 0) @@ -887,23 +910,23 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST $vat_rate=eregi_replace('\*','',$vat_rate); $result = $fac->updateline($_POST['rowid'], - $_POST['desc'], - $_POST['price'], - $_POST['qty'], - $_POST['remise_percent'], - $date_start, - $date_end, - $vat_rate, + $_POST['desc'], + $_POST['price'], + $_POST['qty'], + $_POST['remise_percent'], + $date_start, + $date_end, + $vat_rate, 'HT', - $info_bits - ); + $info_bits + ); if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } - facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); + facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); $_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition } @@ -957,29 +980,29 @@ if ($_POST['addfile']) // Set tmp user directory $conf->users->dir_tmp=DOL_DATA_ROOT."/users/".$user->id; $upload_dir = $conf->users->dir_tmp.'/temp/'; - + if (! empty($_FILES['addedfile']['tmp_name'])) { - if (! is_dir($upload_dir)) create_exdir($upload_dir); - - if (is_dir($upload_dir)) - { - if (dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0) > 0) - { - $mesg = '
'.$langs->trans("FileTransferComplete").'
'; - //print_r($_FILES); + if (! is_dir($upload_dir)) create_exdir($upload_dir); + + if (is_dir($upload_dir)) + { + if (dol_move_uploaded_file($_FILES['addedfile']['tmp_name'], $upload_dir . "/" . $_FILES['addedfile']['name'],0) > 0) + { + $mesg = '
'.$langs->trans("FileTransferComplete").'
'; + //print_r($_FILES); include_once(DOL_DOCUMENT_ROOT.'/html.formmail.class.php'); $formmail = new FormMail($db); $formmail->add_attached_files($upload_dir . "/" . $_FILES['addedfile']['name'],$_FILES['addedfile']['name'],$_FILES['addedfile']['type']); - } - else - { - // Echec transfert (fichier dépassant la limite ?) - $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; - // print_r($_FILES); - } - } + } + else + { + // Echec transfert (fichier dépassant la limite ?) + $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; + // print_r($_FILES); + } + } } $_GET["action"]='presend'; } @@ -1001,7 +1024,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a if (is_readable($file)) { $fac->fetch_client(); - + if ($_POST['sendto']) { // Le destinataire a été fourni via le champ libre @@ -1026,7 +1049,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a if (strlen($sendto)) { $langs->load("commercial"); - + $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; $message = $_POST['message']; @@ -1064,13 +1087,13 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a $filepath[0] = $file; $filename[0] = $fac->ref.'.pdf'; $mimetype[0] = 'application/pdf'; - if ($_FILES['addedfile']['tmp_name']) + if ($_FILES['addedfile']['tmp_name']) { $filepath[1] = $_FILES['addedfile']['tmp_name']; $filename[1] = $_FILES['addedfile']['name']; $mimetype[1] = $_FILES['addedfile']['type']; } - + // Envoi de la facture require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); @@ -1086,14 +1109,14 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a $mesg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; $error=0; - - // Initialisation donnees + + // Initialisation donnees $fac->sendtoid=$sendtoid; $fac->actiontypecode=$actiontypecode; $fac->actionmsg = $actionmsg; $fac->actionmsg2= $actionmsg2; $fac->facid=$fac->id; - + // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($db); @@ -1116,7 +1139,7 @@ if (($_POST['action'] == 'send' || $_POST['action'] == 'relance') && ! $_POST['a { $langs->load("other"); $mesg='
'; - if ($mailfile->error) + if ($mailfile->error) { $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); $mesg.='
'.$mailfile->error; @@ -1171,19 +1194,23 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post } $result=facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs); - if ($result <= 0) - { - dolibarr_print_error($db,$result); - exit; - } - else - { - Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'#builddoc'); - } + if ($result <= 0) + { + dolibarr_print_error($db,$result); + exit; + } + else + { + Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$fac->id.'#builddoc'); + } } +/* + * View + */ + llxHeader('',$langs->trans('Bill'),'HelpInvoice'); $html = new Form($db); @@ -1191,10 +1218,10 @@ $formfile = new FormFile($db); /********************************************************************* -* -* Mode creation -* -**********************************************************************/ + * + * Mode creation + * + **********************************************************************/ if ($_GET['action'] == 'create') { $facturestatic=new Facture($db); @@ -1257,7 +1284,7 @@ if ($_GET['action'] == 'create') $mode_reglement_id = $soc->mode_reglement; $remise_percent = $soc->remise_client; $remise_absolue = 0; - $dateinvoice=mktime(); + $dateinvoice=-1; } $absolute_discount=$soc->getAvailableDiscounts(); @@ -1269,22 +1296,22 @@ if ($_GET['action'] == 'create') print ''; - // Ref + // Ref print ''; - /* - \todo - L'info "Reference commande client" est une carac de la commande et non de la facture. - Elle devrait donc etre stockée sur l'objet commande liée à la facture et non sur la facture. - Pour ceux qui veulent l'utiliser au niveau de la facture, positionner la - constante FAC_USE_CUSTOMER_ORDER_REF à 1. - */ - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) - { - print ''; - } + /* + \todo + L'info "Reference commande client" est une carac de la commande et non de la facture. + Elle devrait donc etre stockée sur l'objet commande liée à la facture et non sur la facture. + Pour ceux qui veulent l'utiliser au niveau de la facture, positionner la + constante FAC_USE_CUSTOMER_ORDER_REF à 1. + */ + if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) + { + print ''; + } // Tiers print ''; print ''."\n"; - // Type de facture + // Type de facture $facids=$facturestatic->list_replacable_invoices($soc->id); if ($facids < 0) { @@ -1320,6 +1347,7 @@ if ($_GET['action'] == 'create') print '
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('RefCustomerOrder').''; - print ''; - print '
'.$langs->trans('RefCustomerOrder').''; + print ''; + print '
'.$langs->trans('Company').''; @@ -1293,7 +1320,7 @@ if ($_GET['action'] == 'create') print '
'.$langs->trans('Type').''; print ''."\n"; + // Type print ''; - // Ligne info remises tiers - print ''; - // Date facture + // Date invoice print ''; @@ -1464,28 +1492,28 @@ if ($_GET['action'] == 'create') if ($_GET['propalid'] > 0) { - print ''."\n"; - print ''."\n"; - print ''."\n"; - //print ''."\n"; - //print ''."\n"; - print ''; - - print ''; - print ''; - print '"; - print '"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + //print ''."\n"; + //print ''."\n"; + print ''; + + print ''; + print ''; + print '"; + print '"; } elseif ($_GET['commandeid'] > 0) - { - print ''."\n"; - print ''."\n"; - print ''."\n"; - //print ''."\n"; - //print ''."\n"; - print ''; - - print ''; + { + print ''."\n"; + print ''."\n"; + print ''."\n"; + //print ''."\n"; + //print ''."\n"; + print ''; + + print ''; print ''; print '"; print '"; @@ -1500,8 +1528,8 @@ if ($_GET['action'] == 'create') print ''."\n"; print ''."\n"; print ''."\n"; -// print ''."\n"; -// print ''."\n"; + // print ''."\n"; + // print ''."\n"; print ''; print ''; @@ -1532,9 +1560,9 @@ if ($_GET['action'] == 'create') print ''; print ''; print ''; @@ -1741,7 +1769,7 @@ else /* */ /* *************************************************************************** */ if ($mesg) print $mesg.'
'; - + $facstatic = new Facture($db); $fac = new Facture($db); @@ -1751,7 +1779,7 @@ else if ($user->societe_id>0 && $user->societe_id!=$fac->socid) accessforbidden('',0); $result=$fac->fetch_client(); - + $soc = new Societe($db, $fac->socid); $soc->fetch($fac->socid); @@ -1763,44 +1791,44 @@ else $resteapayer = $fac->total_ttc - $totalpaye - $totalavoir; if ($fac->paye) $resteapayer=0; $resteapayeraffiche=$resteapayer; - + $author = new User($db); if ($fac->user_author) { $author->id = $fac->user_author; $author->fetch(); } - + $facidnext=$fac->getIdReplacingInvoice(); - - + + $head = facture_prepare_head($fac); - + dolibarr_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer')); - + /* - * Confirmation de la conversion de l'avoir en reduc - */ + * Confirmation de la conversion de l'avoir en reduc + */ if ($_GET['action'] == 'converttoreduc') { $text=$langs->trans('ConfirmConvertToReduc'); $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('ConvertToReduc'),$text,'confirm_converttoreduc'); print '
'; } - + /* - * Confirmation de la suppression de la facture - */ + * Confirmation de la suppression de la facture + */ if ($_GET['action'] == 'delete') { $text=$langs->trans('ConfirmDeleteBill'); $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$fac->id,$langs->trans('DeleteBill'),$text,'confirm_delete'); print '
'; } - + /* - * Confirmation de la validation - */ + * Confirmation de la validation + */ if ($_GET['action'] == 'valid') { // on vérifie si la facture est en numérotation provisoire @@ -1813,7 +1841,7 @@ else { $numfa = $fac->ref; } - + $text=$langs->trans('ConfirmValidateBill',$numfa); if ($conf->notification->enabled) { @@ -1822,14 +1850,14 @@ else $text.='
'; $text.=$notify->confirmMessage(2,$fac->socid); } - + $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ValidateBill'),$text,'confirm_valid'); print '
'; } - + /* - * Confirmation du classement payé - */ + * Confirmation du classement payé + */ if ($_GET['action'] == 'payed' && $resteapayer <= 0) { $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedBill',$fac->ref),'confirm_payed'); @@ -1871,13 +1899,13 @@ else $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedPartially',$fac->ref),'confirm_payed_partially',$formquestion); print '
'; } - + /* - * Confirmation du classement abandonne - */ + * Confirmation du classement abandonne + */ if ($_GET['action'] == 'canceled') { - // S'il y a une facture de remplacement pas encore validée (etat brouillon), + // S'il y a une facture de remplacement pas encore validée (etat brouillon), // on ne permet pas de classer abandonner la facture. if ($facidnext) { @@ -1890,7 +1918,7 @@ else print '
'.$langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated").'
'; } else - { + { // Code $close[1]['code']='badcustomer'; $close[2]['code']='abandon'; @@ -1915,22 +1943,22 @@ else print '
'; } } - + /* - * Confirmation de la suppression d'une ligne produit - */ + * Confirmation de la suppression d'une ligne produit + */ if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) { $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&rowid='.$_GET["rowid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); print '
'; } - + /* - * Facture - */ - + * Facture + */ + print '
'; print ''; print ''; @@ -1356,7 +1384,7 @@ if ($_GET['action'] == 'create') print '>'; print ''; $text=$langs->transnoentities("InvoiceAvoirAsk").' '; -// $text.=''; + // $text.=''; $text.='
'.$langs->trans('Discounts').''; + // Discounts for third party + print '
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); print '. '; @@ -1388,7 +1416,7 @@ if ($_GET['action'] == 'create') print '.'; print '
'.$langs->trans('Date').''; $html->select_date($dateinvoice,'','','','',"add"); print '
'.$langs->trans('Proposal').''.img_object($langs->trans("ShowPropal"),'propal').' '.$propal->ref.'
'.$langs->trans('TotalHT').''.price($propal->price).'
'.$langs->trans('TotalVAT').''.price($propal->total_tva)."
'.$langs->trans('TotalTTC').''.price($propal->total)."
'.$langs->trans('Proposal').''.img_object($langs->trans("ShowPropal"),'propal').' '.$propal->ref.'
'.$langs->trans('TotalHT').''.price($propal->price).'
'.$langs->trans('TotalVAT').''.price($propal->total_tva)."
'.$langs->trans('TotalTTC').''.price($propal->total)."
'.$langs->trans('Order').''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'
'.$langs->trans('Order').''.img_object($langs->trans("ShowOrder"),'order').' '.$commande->ref.'
'.$langs->trans('TotalHT').''.price($commande->total_ht).'
'.$langs->trans('TotalVAT').''.price($commande->total_tva)."
'.$langs->trans('TotalTTC').''.price($commande->total_ttc)."
'.$langs->trans('Contract').''.img_object($langs->trans("ShowContract"),'contract').' '.$contrat->ref.'
'; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) - $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); + $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); else - $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); + $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); print '%
'; - + // Reference print ''; print ''; - + // Ref client /* - \todo - L'info "Reference commande client" est une carac de la commande et non de la facture. - Elle devrait donc etre stockée sur l'objet commande lié à la facture et non sur la facture. - Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF à 1. - */ + \todo + L'info "Reference commande client" est une carac de la commande et non de la facture. + Elle devrait donc etre stockée sur l'objet commande lié à la facture et non sur la facture. + Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF à 1. + */ if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) { print ''; print ''; } - + // Tiers Société print ''; print ''; print ''; - + // Type print ''; - + // Ligne info remises tiers print ''; - + // Dates print ''; print ''; - + $nbrows=8; if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; if ($conf->projet->enabled) $nbrows++; - + print '
'.$langs->trans('Ref').''.$fac->ref; @@ -1945,14 +1973,14 @@ else dolibarr_print_error('',$discount->error); } print '
'; @@ -1977,12 +2005,12 @@ else print '
'.$langs->trans('Company').''.$soc->getNomUrl(1,'compta').'
'.$langs->trans('Type').''; print $fac->getLibType(); @@ -2020,7 +2048,7 @@ else print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; } print '
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); @@ -2057,20 +2085,20 @@ else } if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'.$langs->trans('Date').''.dolibarr_print_date($fac->date,'daytext').''; - + /* - * 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 ''; @@ -2108,7 +2136,7 @@ else print ''; $i++; } - + // Already payed print ''; @@ -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 ''; - + // Date limite reglement print ''; print ''; @@ -2217,7 +2245,7 @@ else print ' '; } print ''; - + // Conditions de règlement print ''; print '
'.($fac->type == 2 ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).'
'.$langs->trans('AlreadyPayed').' :'.price($totalpaye).''.$langs->trans('Currency'.$conf->monnaie).'
'.$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 '
'.$langs->trans('DateMaxPayment').'
'; 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 ''; print ''; @@ -2298,18 +2326,18 @@ else print ''; print ''; print ''; - + // Statut print ''; print ''; - + // Projet if ($conf->projet->enabled) { $langs->load('projects'); print ''; print ''; @@ -2664,7 +2692,7 @@ else print ''; print ''; print ''; - + print ''; print ''; print ''; @@ -2681,20 +2709,20 @@ else { $html->select_produits('','idprod','',$conf->produit->limit_size); } - + if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; - - // éditeur wysiwyg - if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) - { - require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('np_desc','',100,'dolibarr_details'); - $doleditor->Create(); - } - else - { - print ''; - } + + // éditeur wysiwyg + if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) + { + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('np_desc','',100,'dolibarr_details'); + $doleditor->Create(); + } + else + { + 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 ''.$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 ''.$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 ''.$langs->trans('Delete').''; } } - + print '
'; } } - - + + if ($_GET['action'] != 'prerelance' && $_GET['action'] != 'presend') { print '
'; @@ -2260,17 +2288,17 @@ else $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none'); } print '
'.$langs->trans('AmountHT').''.price($fac->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($fac->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.($fac->getLibStatut(4,$totalpaye)).'
'; - + print ''; @@ -2320,7 +2348,7 @@ else print ''; } print '
'; print $langs->trans('Project'); 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 '
'.$langs->trans('ReductionShort').' 
'; print ''; 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 ''; // 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').''.$langs->trans('AmountHT').'
'; - + 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 '
'; - + $facturestatic->id=$objp->facid; $facturestatic->ref=$objp->facnumber; $facturestatic->type=$objp->type; - + print ''; 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 $facturestatic->getNomUrl(1); print $objp->increment; 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() {