From 17528986cbd57d984b93bf4374a7aa45f72b3559 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 8 Jul 2008 23:02:16 +0000 Subject: [PATCH] Fix: Numbering errors --- htdocs/admin/fournisseur.php | 5 +- htdocs/fourn/commande/fiche.php | 1276 +++++++++-------- .../mod_commande_fournisseur_muguet.php | 61 +- htdocs/fourn/fournisseur.commande.class.php | 4 +- .../modules/fichinter/mod_pacific.php | 39 +- 5 files changed, 682 insertions(+), 703 deletions(-) diff --git a/htdocs/admin/fournisseur.php b/htdocs/admin/fournisseur.php index 38e91bb24eb..0d707cc454b 100644 --- a/htdocs/admin/fournisseur.php +++ b/htdocs/admin/fournisseur.php @@ -215,12 +215,13 @@ if ($handle) print ''; $commande=new CommandeFournisseur($db); - + $commande->initAsSpecimen(); + // Info $htmltooltip=''; $htmltooltip.=''.$langs->trans("Version").': '.$module->getVersion().'
'; $facture->type=0; - $nextval=$module->getNextValue($mysoc,$propale); + $nextval=$module->getNextValue($mysoc,$commande); if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval { $htmltooltip.=''.$langs->trans("NextValue").': '; diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 633a9faf611..28873f461d3 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -20,11 +20,11 @@ */ /** - \file htdocs/fourn/commande/fiche.php - \ingroup commande - \brief Fiche commande - \version $Id$ -*/ + \file htdocs/fourn/commande/fiche.php + \ingroup commande + \brief Fiche commande + \version $Id$ + */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); @@ -50,15 +50,15 @@ $id = isset($_GET["id"])?$_GET["id"]:$_POST["id"]; $socid=0; if ($user->societe_id > 0) { - $action = ''; - $socid = $user->societe_id; + $action = ''; + $socid = $user->societe_id; } // Recuperation de l'id de projet $projetid = 0; if ($_GET["projetid"]) { - $projetid = $_GET["projetid"]; + $projetid = $_GET["projetid"]; } $mesg=''; @@ -71,17 +71,17 @@ $mesg=''; // Set project if ($_POST['action'] == 'classin') { - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - $commande->setProject($_POST["projetid"]); + $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $commande->setProject($_POST["projetid"]); } if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->commande->creer) { - $commande = new CommandeFournisseur($db); - $commande->fetch($_REQUEST['id']); - $result = $commande->set_remise($user, $_POST['remise_percent']); - $id=$_REQUEST['id']; + $commande = new CommandeFournisseur($db); + $commande->fetch($_REQUEST['id']); + $result = $commande->set_remise($user, $_POST['remise_percent']); + $id=$_REQUEST['id']; } /* @@ -90,72 +90,72 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->com if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->creer) { if ($_POST['qty'] && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice'])) - { - $commande = new CommandeFournisseur($db); - $ret=$commande->fetch($id); - if ($ret < 0) - { - dolibarr_print_error($db,$commande->error); - exit; - } - - $soc = new Societe($db, $commande->socid); - $result=$soc->fetch($commande->socid); - //print $result; - - // Ecrase $pu par celui du produit - // Ecrase $desc par celui du produit - // Ecrase $txtva par celui du produit - if ($_POST["idprodfournprice"] > 0) - { - $prodfournprice = new ProductFournisseur($db); - $prodfournprice->fetch_product_fournisseur_price($_POST["idprodfournprice"]); - - $prod = new Product($db, $prodfournprice->product_id); - $prod->fetch($prodfournprice->product_id); - - $libelle = $prod->libelle; - - $desc = $prod->description; - $desc.= $prod->description && $_POST['np_desc'] ? "\n" : ""; - $desc.= $_POST['np_desc']; - - $tva_tx = get_default_tva($soc,$mysoc,$prod->tva_tx,$prodfournprice->product_id); - } - else { - $pu=$_POST['pu']; - $tva_tx=$_POST['tva_tx']; - $desc=$_POST['dp_desc']; - } - //print "xx".$tva_tx; exit; - - $result=$commande->addline( - $desc, - $pu, - $_POST['qty'], - $tva_tx, - $prodfournprice->product_id, - $_POST['idprodfournprice'], - $prodfournprice->fourn_ref, - $_POST['remise_percent'], + $commande = new CommandeFournisseur($db); + $ret=$commande->fetch($id); + if ($ret < 0) + { + dolibarr_print_error($db,$commande->error); + exit; + } + + $soc = new Societe($db, $commande->socid); + $result=$soc->fetch($commande->socid); + //print $result; + + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $txtva par celui du produit + if ($_POST["idprodfournprice"] > 0) + { + $prodfournprice = new ProductFournisseur($db); + $prodfournprice->fetch_product_fournisseur_price($_POST["idprodfournprice"]); + + $prod = new Product($db, $prodfournprice->product_id); + $prod->fetch($prodfournprice->product_id); + + $libelle = $prod->libelle; + + $desc = $prod->description; + $desc.= $prod->description && $_POST['np_desc'] ? "\n" : ""; + $desc.= $_POST['np_desc']; + + $tva_tx = get_default_tva($soc,$mysoc,$prod->tva_tx,$prodfournprice->product_id); + } + else + { + $pu=$_POST['pu']; + $tva_tx=$_POST['tva_tx']; + $desc=$_POST['dp_desc']; + } + //print "xx".$tva_tx; exit; + + $result=$commande->addline( + $desc, + $pu, + $_POST['qty'], + $tva_tx, + $prodfournprice->product_id, + $_POST['idprodfournprice'], + $prodfournprice->fourn_ref, + $_POST['remise_percent'], 'HT' ); - if ($result > 0) - { - if ($_REQUEST['lang_id']) - { + if ($result > 0) + { + if ($_REQUEST['lang_id']) + { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); - } - else - { - $mesg='
'.$commande->error.'
'; - } - } + } + supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + } + else + { + $mesg='
'.$commande->error.'
'; + } + } } /* @@ -163,37 +163,37 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree */ if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['save'] == $langs->trans('Save')) { - $commande = new CommandeFournisseur($db,"",$id); - if ($commande->fetch($id) < 0) dolibarr_print_error($db); + $commande = new CommandeFournisseur($db,"",$id); + if ($commande->fetch($id) < 0) dolibarr_print_error($db); - $result = $commande->updateline($_POST['elrowid'], - $_POST['eldesc'], - $_POST['pu'], - $_POST['qty'], - $_POST['remise_percent'], - $_POST['tva_tx'] - ); + $result = $commande->updateline($_POST['elrowid'], + $_POST['eldesc'], + $_POST['pu'], + $_POST['qty'], + $_POST['remise_percent'], + $_POST['tva_tx'] + ); - if ($result >= 0) - { - if ($_REQUEST['lang_id']) + if ($result >= 0) { + if ($_REQUEST['lang_id']) + { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + } + else + { + dolibarr_print_error($db,$commande->error); + exit; } - supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); - } - else - { - dolibarr_print_error($db,$commande->error); - exit; - } } if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['cancel'] == $langs->trans('Cancel')) { - Header('Location: fiche.php?id='.$id); // Pour reaffichage de la fiche en cours d'edition - exit; + Header('Location: fiche.php?id='.$id); // Pour reaffichage de la fiche en cours d'edition + exit; } if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) @@ -202,23 +202,25 @@ if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes { $commande = new CommandeFournisseur($db); $commande->fetch($id); - $result = $commande->delete_line($_GET['lineid']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - supplier_order_pdf_create($db, $id, $commande->modelpdf, $outputlangs); - } - Header('Location: fiche.php?id='.$id); - exit; + $result = $commande->delete_line($_GET['lineid']); + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + supplier_order_pdf_create($db, $id, $commande->modelpdf, $outputlangs); + } + Header('Location: fiche.php?id='.$id); + exit; } if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->valider) { $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $commande->date_commande=time(); $result = $commande->valid($user); if ($result >= 0) { @@ -233,33 +235,33 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user-> if ($_POST['action'] == 'confirm_approve' && $_POST["confirm"] == 'yes' && $user->rights->fournisseur->commande->approuver) { - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - $result = $commande->approve($user); + $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $result = $commande->approve($user); } if ($_POST['action'] == 'confirm_refuse' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->approuver) { - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - $result = $commande->refuse($user); + $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $result = $commande->refuse($user); } if ($_POST['action'] == 'confirm_commande' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->commander) { - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]); + $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]); } if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->commande->creer) { - $commande = new CommandeFournisseur($db); - $commande->id = $id; - $commande->delete(); - Header('Location: index.php'); - exit; + $commande = new CommandeFournisseur($db); + $commande->id = $id; + $commande->delete(); + Header('Location: index.php'); + exit; } if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) @@ -292,11 +294,11 @@ if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->rec if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler) { - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - $result = $commande->cancel($user); - Header("Location: fiche.php?id=".$id); - exit; + $commande = new CommandeFournisseur($db); + $commande->fetch($id); + $result = $commande->cancel($user); + Header("Location: fiche.php?id=".$id); + exit; } /* @@ -305,80 +307,80 @@ if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->r if ($_GET['action'] == 'up' && $user->rights->fournisseur->commande->creer) { - $commande = new CommandeFournisseur($db,'',$id); - $commande->fetch($id); - $commande->line_up($_GET['rowid']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); - Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); - exit; + $commande = new CommandeFournisseur($db,'',$id); + $commande->fetch($id); + $commande->line_up($_GET['rowid']); + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); + exit; } if ($_GET['action'] == 'down' && $user->rights->fournisseur->commande->creer) { - $commande = new CommandeFournisseur($db,'',$id); - $commande->fetch($id); - $commande->line_down($_GET['rowid']); - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); - Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); - exit; + $commande = new CommandeFournisseur($db,'',$id); + $commande->fetch($id); + $commande->line_down($_GET['rowid']); + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + supplier_order_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.$_GET['rowid']); + exit; } if ($_REQUEST['action'] == 'builddoc') // En get ou en post { - /* - * Generation de la commande - * definit dans /includes/modules/commande/modules_commande.php - */ + /* + * Generation de la commande + * definit dans /includes/modules/commande/modules_commande.php + */ - // Sauvegarde le dernier module choisi pour generer un document - $commande = new CommandeFournisseur($db, 0, $_REQUEST['id']); - $commande->fetch($_REQUEST['id']); - if ($_REQUEST['model']) - { - $commande->setDocModel($user, $_REQUEST['model']); - } + // Sauvegarde le dernier module choisi pour generer un document + $commande = new CommandeFournisseur($db, 0, $_REQUEST['id']); + $commande->fetch($_REQUEST['id']); + if ($_REQUEST['model']) + { + $commande->setDocModel($user, $_REQUEST['model']); + } - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - $result=supplier_order_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs); - if ($result <= 0) - { - dolibarr_print_error($db,$result); - exit; - } - else - { - Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc'); - exit; - } + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + $result=supplier_order_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs); + if ($result <= 0) + { + dolibarr_print_error($db,$result); + exit; + } + else + { + Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc'); + exit; + } } // Efface les fichiers if ($action=='remove_file') { - $commande = new CommandeFournisseur($db); + $commande = new CommandeFournisseur($db); - if ($commande->fetch($id)) - { - $upload_dir = $conf->commande->dir_output . "/"; - $file = $upload_dir . '/' . urldecode($_GET['file']); - dol_delete_file($file); - $mesg = '
'.$langs->trans("FileWasRemoved").'
'; - } + if ($commande->fetch($id)) + { + $upload_dir = $conf->commande->dir_output . "/"; + $file = $upload_dir . '/' . urldecode($_GET['file']); + dol_delete_file($file); + $mesg = '
'.$langs->trans("FileWasRemoved").'
'; + } } @@ -391,7 +393,7 @@ if ($_GET["action"] == 'create') $fourn->fetch($_GET["socid"]); $db->begin(); - + $orderid=$fourn->create_commande($user); if ($orderid > 0) { @@ -434,172 +436,174 @@ $formfile = new FormFile($db); if ($id > 0) { //if ($mesg) print $mesg.'
'; - $commande = new CommandeFournisseur($db); - if ( $commande->fetch($id) >= 0) + + if ($commande->fetch($id) >= 0) { - $soc = new Societe($db); - $soc->fetch($commande->socid); + $soc = new Societe($db); + $soc->fetch($commande->socid); - $author = new User($db); - $author->id = $commande->user_author_id; - $author->fetch(); + $author = new User($db); + $author->id = $commande->user_author_id; + $author->fetch(); - $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id; - $head[$h][1] = $langs->trans("OrderCard"); - $a = $h; - $h++; + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id; + $head[$h][1] = $langs->trans("OrderCard"); + $a = $h; + $h++; - $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$commande->id; - $head[$h][1] = $langs->trans("OrderDispatch"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id; - $head[$h][1] = $langs->trans("Note"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/history.php?id='.$commande->id; - $head[$h][1] = $langs->trans("OrderFollow"); - $h++; - - - $title=$langs->trans("SupplierOrder"); - dolibarr_fiche_head($head, $a, $title); - - /* - * Confirmation de la suppression de la commande - */ - if ($_GET['action'] == 'delete') - { - $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete'); - print '
'; - } + $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$commande->id; + $head[$h][1] = $langs->trans("OrderDispatch"); + $h++; - /* - * Confirmation de la validation - */ - if ($_GET['action'] == 'valid') - { - // on verifie si la commande est en numerotation provisoire - $ref = substr($commande->ref, 1, 4); - if ($ref == 'PROV') + $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id; + $head[$h][1] = $langs->trans("Note"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/history.php?id='.$commande->id; + $head[$h][1] = $langs->trans("OrderFollow"); + $h++; + + + $title=$langs->trans("SupplierOrder"); + dolibarr_fiche_head($head, $a, $title); + + /* + * Confirmation de la suppression de la commande + */ + if ($_GET['action'] == 'delete') { - $newref = $commande->getNextNumRef($soc); + $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete'); + print '
'; } - else - { - $newref = $commande->ref; - } - - $text=$langs->trans('ConfirmValidateOrder',$newref); - if ($conf->notification->enabled) - { - require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); - $notify=new Notify($db); - $text.='
'; - $text.=$notify->confirmMessage(3,$commande->socid); - } - - $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid'); - print '
'; - } - /* - * Confirmation de l'approbation - * - */ - if ($_GET['action'] == 'approve') - { - $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder"),"confirm_approve"); - print '
'; - } - /* - * Confirmation de la desapprobation - * - */ - if ($_GET['action'] == 'refuse') - { - $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder"),"confirm_refuse"); - print '
'; - } - /* - * Confirmation de l'annulation - */ - if ($_GET['action'] == 'cancel') - { - $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder"),"confirm_cancel"); - print '
'; - } - - /* - * Confirmation de l'envoi de la commande - */ - if ($_GET["action"] == 'commande') - { - $date_com = dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); - $html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"], - $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dolibarr_print_date($date_com,'day')),"confirm_commande"); - print '
'; - } - - /* - * 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"].'?id='.$commande->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); - print '
'; - } - - /* - * Commande - */ - $nbrow=8; - if ($conf->projet->enabled) $nbrow++; - print ''; - - // Ref - print ''; - print ''; - print ''; - - // Fournisseur - print '"; - print ''; - print ''; - - // Statut - print ''; - print ''; - print '"; - if ($commande->methode_commande_id > 0) - { - print '
'.$langs->trans("Ref").''.$commande->ref.'
'.$langs->trans("Supplier")."'; - print ''; - print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'
'.$langs->trans("Status").''; - print $commande->getLibStatut(4); - print "
'.$langs->trans("Date").''; - - if ($commande->date_commande) + /* + * Confirmation de la validation + */ + if ($_GET['action'] == 'valid') { + $commande->date_commande=time(); + + // on verifie si la commande est en numerotation provisoire + $ref = substr($commande->ref, 1, 4); + if ($ref == 'PROV') + { + $newref = $commande->getNextNumRef($soc); + } + else + { + $newref = $commande->ref; + } + + $text=$langs->trans('ConfirmValidateOrder',$newref); + if ($conf->notification->enabled) + { + require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); + $notify=new Notify($db); + $text.='
'; + $text.=$notify->confirmMessage(3,$commande->socid); + } + + $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid'); + print '
'; + } + /* + * Confirmation de l'approbation + * + */ + if ($_GET['action'] == 'approve') + { + $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder"),"confirm_approve"); + print '
'; + } + /* + * Confirmation de la desapprobation + * + */ + if ($_GET['action'] == 'refuse') + { + $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder"),"confirm_refuse"); + print '
'; + } + /* + * Confirmation de l'annulation + */ + if ($_GET['action'] == 'cancel') + { + $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder"),"confirm_cancel"); + print '
'; + } + + /* + * Confirmation de l'envoi de la commande + */ + if ($_GET["action"] == 'commande') + { + $date_com = dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); + $html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"], + $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dolibarr_print_date($date_com,'day')),"confirm_commande"); + print '
'; + } + + /* + * 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"].'?id='.$commande->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); + print '
'; + } + + /* + * Commande + */ + $nbrow=8; + if ($conf->projet->enabled) $nbrow++; + print ''; + + // Ref + print ''; + print ''; + print ''; + + // Fournisseur + print '"; + print ''; + print ''; + + // Statut + print ''; + print ''; + print '"; + + if ($commande->methode_commande_id > 0) + { + print '"; } - print ""; - } - - // Auteur - print ''; - print ''; - print '"; - + + // Auteur + print ''; + print ''; + print '"; + // Projet if ($conf->projet->enabled) { @@ -622,69 +626,69 @@ if ($id > 0) print ''; } - // Ligne de 3 colonnes - print ''; - print ''; - print ''; + // Ligne de 3 colonnes + print ''; + print ''; + print ''; - print ''; - print ''; - - print ''; - print ''; - - print "
'.$langs->trans("Ref").''.$commande->ref.'
'.$langs->trans("Supplier")."'; + print ''; + print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'
'.$langs->trans("Status").''; + print $commande->getLibStatut(4); + print "
'.$langs->trans("Date").''; + + if ($commande->date_commande) + { print dolibarr_print_date($commande->date_commande,"dayhour")."\n"; - } - - print ''; - if ($commande->methode_commande) - { + } + + print ''; + if ($commande->methode_commande) + { print $langs->trans("Method")." : " .$commande->methode_commande; + } + print "
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).''; - print " 
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).''; + print " 
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountVAT").''.price($commande->total_tva).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($commande->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
"; - - if ($mesg) print $mesg; - else print '
'; - - /* - * Lignes de commandes - */ - print ''; - - $sql = "SELECT l.ref as ref_fourn, l.fk_product, l.description, l.qty"; - $sql.= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice"; - $sql.= ", l.total_ht, l.total_tva, l.total_ttc"; - $sql.= ", p.rowid as product_id, p.label as product, p.ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; + print ''; + print ''; + + print ''; + print ''; + + print "
'.$langs->trans("AmountVAT").''.price($commande->total_tva).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($commande->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
"; + + if ($mesg) print $mesg; + else print '
'; + + /* + * Lignes de commandes + */ + print ''; + + $sql = "SELECT l.ref as ref_fourn, l.fk_product, l.description, l.qty"; + $sql.= ", l.rowid, l.tva_tx, l.remise_percent, l.subprice"; + $sql.= ", l.total_ht, l.total_tva, l.total_ttc"; + $sql.= ", p.rowid as product_id, p.label as product, p.ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; - $sql.= " WHERE l.fk_commande = ".$commande->id; - $sql.= " ORDER BY l.rowid"; + $sql.= " WHERE l.fk_commande = ".$commande->id; + $sql.= " ORDER BY l.rowid"; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; $total = 0; - - if ($num) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - // Ligne en mode visu - if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; $total = 0; + + if ($num) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + // Ligne en mode visu + if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { print '"; } else @@ -725,7 +729,7 @@ if ($id > 0) print ''; - + print ''; @@ -736,18 +740,18 @@ if ($id > 0) } print ""; } - + // Ligne en mode update if ($_GET["action"] == 'editline' && $user->rights->fournisseur->commande->creer && $_GET["rowid"] == $objp->rowid) - { - print 'rowid.'" method="post">'; - print ''; + { + print 'rowid.'" method="post">'; + print ''; print ''; print ''; - print ''; - print ''; + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - print "\n"; - } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '' . "\n"; + print "\n"; + } $i++; + } + $db->free(); } - $db->free(); - } - else - { - dolibarr_print_error($db); - } - - /* - * Ajouter une ligne - */ - if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'editline') - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ajout produit produits/services personnalises - print ''; - print ''; - print ''; - - $var=true; + else + { + dolibarr_print_error($db); + } + + /* + * Ajouter une ligne + */ + if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'editline') + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Ajout produit produits/services personnalises + print ''; + print ''; + print ''; + + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + // Ajout de produits/services predefinis + if ($conf->produit->enabled) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + $var=!$var; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; - - // Ajout de produits/services predefinis - if ($conf->produit->enabled) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - } } - print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').' 
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').' 
'; print ''; // ancre pour retourner sur la ligne - + // Affiche ligne produit $text = ''; $text.= img_object($langs->trans('ShowProduct'),'product'); @@ -697,7 +701,7 @@ if ($id > 0) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; } - + print "
rowid.'#'.$objp->rowid.'">'; print img_edit(); print 'rowid.'">'; print img_delete(); print '
'; - print ''; // ancre pour retourner sur la ligne - if ($objp->fk_product > 0) + print '
'; + print ''; // ancre pour retourner sur la ligne + if ($objp->fk_product > 0) { print ''; print img_object($langs->trans('ShowProduct'),'product'); @@ -767,271 +771,271 @@ if ($id > 0) { print ''; } - print ''; - $html->select_tva('tva_tx',$objp->tva_tx); - print '%'; - print '
'; + $html->select_tva('tva_tx',$objp->tva_tx); + print '%'; + print '
'; - print ''; // ancre - print $langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; + print ''; // ancre + print $langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; + // editeur wysiwyg + if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) + { + require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); + $doleditor=new DolEditor('dp_desc','',100,'dolibarr_details'); + $doleditor->Create(); + } + else + { + print ''; + } + print ''; + if($soc->tva_assuj == "0") + print '0'; + else + print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); + print '%
'; + if ($conf->service->enabled) + { + print $langs->trans('RecordedProductsAndServices'); + } + else + { + print $langs->trans('RecordedProducts'); + } + print ''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; + print ''; + $html->select_produits_fournisseurs($commande->fourn_id,'','idprodfournprice'); + + if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; + // editeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); - $doleditor=new DolEditor('dp_desc','',100,'dolibarr_details'); + $doleditor=new DolEditor('np_desc','',100,'dolibarr_details'); $doleditor->Create(); } else { - print ''; + print ''; } + print '
'; - if($soc->tva_assuj == "0") - print '0'; - else - print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); - print '%%
'; - if ($conf->service->enabled) - { - print $langs->trans('RecordedProductsAndServices'); - } - else - { - print $langs->trans('RecordedProducts'); - } - print ''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; - $html->select_produits_fournisseurs($commande->fourn_id,'','idprodfournprice'); - - if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; - - // editeur 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 ''; - - - /** - * Boutons actions - */ - if ($user->societe_id == 0 && $commande->statut < 3 && $_GET['action'] <> 'editline') - { - print '
'; - - if ($commande->statut == 0 && $num > 0) + } + print '
'; + print ''; + + + /** + * Boutons actions + */ + if ($user->societe_id == 0 && $commande->statut < 3 && $_GET['action'] <> 'editline') { + print '
'; + + if ($commande->statut == 0 && $num > 0) + { if ($user->rights->fournisseur->commande->valider) - { - print ''.$langs->trans("Valid").''; - } - } - - if ($commande->statut == 1) - { + { + print ''.$langs->trans("Valid").''; + } + } + + if ($commande->statut == 1) + { if ($user->rights->fournisseur->commande->approuver) - { - print ''.$langs->trans("ApproveOrder").''; - - print ''.$langs->trans("RefuseOrder").''; - } - - if ($user->rights->fournisseur->commande->annuler) - { - print ''.$langs->trans("CancelOrder").''; - } - - } + { + print ''.$langs->trans("ApproveOrder").''; + + print ''.$langs->trans("RefuseOrder").''; + } - if ($commande->statut == 2) - { if ($user->rights->fournisseur->commande->annuler) - { - print ''.$langs->trans("CancelOrder").''; - } - } - - if ($commande->statut == 0) - { + { + print ''.$langs->trans("CancelOrder").''; + } + + } + + if ($commande->statut == 2) + { + if ($user->rights->fournisseur->commande->annuler) + { + print ''.$langs->trans("CancelOrder").''; + } + } + + if ($commande->statut == 0) + { if ($user->rights->fournisseur->commande->creer) - { - print ''.$langs->trans("Delete").''; - } + { + print ''.$langs->trans("Delete").''; + } + } + + print "
"; } - - print ""; - } - - print '
'; - print ''; // ancre - /* - * Documents generes - * - */ - $comfournref = sanitize_string($commande->ref); - $file = $conf->fournisseur->commande->dir_output . '/' . $comfournref . '/' . $comfournref . '.pdf'; - $relativepath = $comfournref.'/'.$comfournref.'.pdf'; - $filedir = $conf->fournisseur->commande->dir_output . '/' . $comfournref; - $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; - $genallowed=$user->rights->fournisseur->commande->creer; - $delallowed=$user->rights->fournisseur->commande->supprimer; - - $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); - - - print ''; - - - /* - * - * - */ - if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) - { - /** - * Commander - */ - print '
'; - print '
'; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - print '
'.$langs->trans("ToOrder").'
'.$langs->trans("OrderDate").''; - print $html->select_date('','','','','',"commande"); - print '
'.$langs->trans("OrderMode").''; - $html->select_methodes_commande('',"methodecommande",1); - print '
'.$langs->trans("Comment").'
'; - print '
'; - } - - /* - * - * - */ - if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) - { - /** - * Receptionner - */ - print '
'; - print '
'; - print ''; - print ''; - print ''; - print '\n"; + print '
'.$langs->trans("Receive").'
'.$langs->trans("DeliveryDate").''; - print $html->select_date('','','','','',"commande"); - print "
'; - print ''; - print ''; - print "
'; + print ''; // ancre - print "
".$langs->trans("Delivery")."\n"; - $liv = array(); - $liv[''] = ' '; - $liv['tot'] = $langs->trans("TotalWoman"); - $liv['par'] = $langs->trans("PartialWoman"); - $liv['nev'] = $langs->trans("NeverReceived"); - $liv['can'] = $langs->trans("Canceled"); - - print $html->select_array("type",$liv); - - - print '
'.$langs->trans("Comment").'
\n"; - print "
\n"; - } - print '
'; + /* + * Documents generes + * + */ + $comfournref = sanitize_string($commande->ref); + $file = $conf->fournisseur->commande->dir_output . '/' . $comfournref . '/' . $comfournref . '.pdf'; + $relativepath = $comfournref.'/'.$comfournref.'.pdf'; + $filedir = $conf->fournisseur->commande->dir_output . '/' . $comfournref; + $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; + $genallowed=$user->rights->fournisseur->commande->creer; + $delallowed=$user->rights->fournisseur->commande->supprimer; + + $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); + + + print ''; + + + /* + * + * + */ + if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) + { + /** + * Commander + */ + print '
'; + print '
'; + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + print '
'.$langs->trans("ToOrder").'
'.$langs->trans("OrderDate").''; + print $html->select_date('','','','','',"commande"); + print '
'.$langs->trans("OrderMode").''; + $html->select_methodes_commande('',"methodecommande",1); + print '
'.$langs->trans("Comment").'
'; + print '
'; + } + + /* + * + * + */ + if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) + { + /** + * Receptionner + */ + print '
'; + print '
'; + print ''; + print ''; + print ''; + print '\n"; + + print "'; + print ''; + print ''; + print "
'.$langs->trans("Receive").'
'.$langs->trans("DeliveryDate").''; + print $html->select_date('','','','','',"commande"); + print "
".$langs->trans("Delivery")."\n"; + $liv = array(); + $liv[''] = ' '; + $liv['tot'] = $langs->trans("TotalWoman"); + $liv['par'] = $langs->trans("PartialWoman"); + $liv['nev'] = $langs->trans("NeverReceived"); + $liv['can'] = $langs->trans("Canceled"); + + print $html->select_array("type",$liv); + + + print '
'.$langs->trans("Comment").'
\n"; + print "
\n"; + } + print ''; } - else + else { - // Commande non trouvee - dolibarr_print_error($db); + // Commande non trouvee + dolibarr_print_error($db); } } diff --git a/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php b/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php index 9b9695bd5ac..9f2c7189104 100644 --- a/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php +++ b/htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php @@ -19,7 +19,7 @@ */ /** - \file htdocs/four/commande/modules/mod_commande_fournisseur_muguet.php + \file htdocs/fourn/commande/modules/mod_commande_fournisseur_muguet.php \ingroup commande \brief Fichier contenant la classe du modèle de numérotation de référence de commande fournisseur Muguet \version $Id$ @@ -84,57 +84,46 @@ class mod_commande_fournisseur_muguet extends ModeleNumRefSuppliersOrders } } - /** \brief Renvoi prochaine valeur attribuée - * \return string Valeur - */ - function getNextValue() + /** \brief Return next value + * \param objsoc Object third party + * \param object Object + * \return string Valeur + */ + function getNextValue($objsoc=0,$object='') { global $db; // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) - $coyymm=''; - $sql = "SELECT MAX(ref)"; + $posindice=8; + $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; - $resql=$db->query($sql); + $sql.= " WHERE ref like '".$this->prefix."%'"; + + $resql=$db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) $coyymm = substr($row[0],0,6); + $obj = $db->fetch_object($resql); + if ($obj) $max = $obj->max; + else $max=0; } - // Si champ respectant le modèle a été trouvée - if (eregi('^'+$this->prefix+'[0-9][0-9][0-9][0-9]',$coyymm)) - { - // Recherche rapide car restreint par un like sur champ indexé - $posindice=8; - $sql = "SELECT MAX(0+SUBSTRING(ref,$posindice))"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " WHERE ref like '${coyymm}%'"; - $resql=$db->query($sql); - if ($resql) - { - $row = $db->fetch_row($resql); - $max = $row[0]; - } - } - else - { - $max=0; - } - $yymm = strftime("%y%m",time()); + //$date=time(); + $date=$object->date_commande; + $yymm = strftime("%y%m",$date); $num = sprintf("%04s",$max+1); - 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) + * \param objsoc Object third party + * \param object Object + * \return string Texte descripif + */ + function commande_get_num($objsoc=0,$object='') { - return $this->getNextValue(); + return $this->getNextValue($objsoc,$object); } } diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index 75bb5f56044..06e2d01c648 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2005-2008 Regis Houssin * @@ -446,7 +446,7 @@ class CommandeFournisseur extends Commande } else { - dolibarr_print_error($db,"Facture::getNextNumRef ".$obj->error); + dolibarr_print_error($db,"CommandeFournisseur::getNextNumRef ".$obj->error); return -1; } } diff --git a/htdocs/includes/modules/fichinter/mod_pacific.php b/htdocs/includes/modules/fichinter/mod_pacific.php index e20da85a6ec..8798749b80a 100644 --- a/htdocs/includes/modules/fichinter/mod_pacific.php +++ b/htdocs/includes/modules/fichinter/mod_pacific.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2005-2008 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -107,37 +107,22 @@ class mod_pacific extends ModeleNumRefFicheinter global $db; // D'abord on récupère la valeur max (réponse immédiate car champ indéxé) - $fayymm=''; - $sql = "SELECT MAX(ref)"; + $posindice=8; + $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; - $resql=$db->query($sql); + $sql.= " WHERE ref like '".$this->prefix."%'"; + + $resql=$db->query($sql); if ($resql) { - $row = $db->fetch_row($resql); - if ($row) $fayymm = substr($row[0],0,6); + $obj = $db->fetch_object($resql); + if ($obj) $max = $obj->max; + else $max=0; } - // Si champ respectant le modèle a été trouvée - if (eregi('^'.$this->prefix.'[0-9][0-9][0-9][0-9]',$fayymm)) - { - // Recherche rapide car restreint par un like sur champ indexé - $posindice=8; - $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice."))"; - $sql.= " FROM ".MAIN_DB_PREFIX."fichinter"; - $sql.= " WHERE ref like '".$fayymm."%'"; - $resql=$db->query($sql); - if ($resql) - { - $row = $db->fetch_row($resql); - $max = $row[0]; - } - } - else - { - $max=0; - } - //$yymm = strftime("%y%m",time()); - $yymm = strftime("%y%m",$ficheinter->date); + //$date=time(); + $date=$ficheinter->date; + $yymm = strftime("%y%m",$date); $num = sprintf("%04s",$max+1); return $this->prefix.$yymm."-".$num;