From 9e39bd7cdc8e0f5431abe12037cb23e8bb279b8d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Sep 2006 01:01:21 +0000 Subject: [PATCH] Uniformisation du code --- htdocs/comm/propal.php | 15 ++++++----- htdocs/commande/fiche.php | 39 ++++++++++++++++++----------- htdocs/compta/facture.php | 52 +++++++++++++++++++++------------------ 3 files changed, 62 insertions(+), 44 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 25f8af9aa76..e54177ec9fe 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -162,9 +162,10 @@ if ($_POST['action'] == 'set_ref_client' && $user->rights->propale->creer) /* * Creation propale */ -if ($_POST['action'] == 'add') +if ($_POST['action'] == 'add' && $user->rights->propale->creer) { - $propal = new Propal($db, $_POST['socidp']); + $propal = new Propal($db); + $propal->socidp=$_POST['socidp']; $propal->fetch_client(); $db->begin(); @@ -477,6 +478,7 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer) // La description de la ligne est celle saisie ou // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini) + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on $desc=$_POST['np_desc']; if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC) { @@ -1042,6 +1044,7 @@ if ($conf->expedition->enabled) else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; print ' - '.nl2br($objp->product); + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on if ($conf->global->FORM_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { print '
'.nl2br($objp->product_desc); @@ -1177,7 +1180,7 @@ if ($conf->expedition->enabled) } else { - print ''; + print ''; } print ''; print ''; @@ -1373,7 +1376,7 @@ if ($conf->expedition->enabled) $var=true; print '\n"; - print ''; + print ''; print ''; if($societe->tva_assuj == "0") { @@ -1413,7 +1416,7 @@ if ($conf->expedition->enabled) $html->select_produits('','idprod','',$conf->produit->limit_size); } if (! $conf->use_ajax) print '
'; - print ''; + print ''; print ''; print ' '; print ''; @@ -1438,7 +1441,7 @@ if ($conf->expedition->enabled) { print '
'; print ''; - print ''; print ''; - print ''; + print ''; print ''; // Client @@ -1260,6 +1270,7 @@ else else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.' - '.nl2br($objp->product); print ($objp->description && $objp->description!=$objp->product)?'
'.nl2br($objp->description):''; + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on if ($conf->global->FORM_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { print '
'.nl2br($objp->product_desc); @@ -1369,7 +1380,7 @@ else } else { - print ''; + print ''; } print ''; print ''; - print ' '; + print ' '; print ''; print ''; print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e83a68a4dad..f936c78cb7f 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -267,9 +267,14 @@ if ($_POST['action'] == 'confirm_payed_partially' && $_POST['confirm'] == 'yes' /* * Insertion facture */ -if ($_POST['action'] == 'add') +if ($_POST['action'] == 'add' && $user->rights->facture->creer) { $facture = new Facture($db); + $facture->socidp=$_POST['socid']; + $facture->fetch_client(); + + $db->begin(); + if ($_POST['type'] == 1) { if ($_POST['fac_replacement'] > 0) @@ -298,8 +303,8 @@ if ($_POST['action'] == 'add') } else { + $error=1; $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).'
'; - $_GET['action'] = 'create'; } } @@ -359,19 +364,7 @@ if ($_POST['action'] == 'add') } } - $facid = $facture->create($user); - - if ($facid > 0) - { - Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facid); - exit; - } - else - { - $_GET["action"]='create'; - $mesg='
'.$facture->error.'
'; - } } else { @@ -382,6 +375,7 @@ if ($_POST['action'] == 'add') { $facture->propalid = $_POST['propalid']; $facid = $facture->create($user); + if ($facid > 0) { $prop = New Propal($db); @@ -408,12 +402,12 @@ if ($_POST['action'] == 'add') } else { - print $langs->trans('UnknownError'); + $error++; } } else { - dolibarr_print_error($facture->db,$facture->error); + $error++; } } @@ -424,6 +418,7 @@ if ($_POST['action'] == 'add') { $facture->commandeid = $_POST['commandeid']; $facid = $facture->create($user); + if ($facid > 0) { $comm = New Commande($db); @@ -451,12 +446,12 @@ if ($_POST['action'] == 'add') } else { - print $langs->trans('UnknownError'); + $error++; } } else { - dolibarr_print_error($facture->db,$facture->error); + $error++; } } @@ -467,6 +462,7 @@ if ($_POST['action'] == 'add') { $facture->contratid = $_POST['contratid']; $facid = $facture->create($user); + if ($facid > 0) { $contrat = New Contrat($db); @@ -501,25 +497,31 @@ if ($_POST['action'] == 'add') } else { - print $langs->trans('UnknownError'); + $error++; } } else { - dolibarr_print_error($facture->db,$facture->error); + $error++; } } - } + } // Fin création facture, on l'affiche - if ($facid > 0) + if ($facid > 0 && ! $error) { + $db->commit(); Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$facid); exit; } - + else + { + $db->rollback(); + $_GET["action"]='create'; + if (! $mesg) $mesg='
'.$facture->error.'
'; + } } /* @@ -581,6 +583,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && // La description de la ligne est celle saisie ou // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini) + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on $desc=$_POST['desc']; if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC) { @@ -1909,9 +1912,10 @@ else print_date_range($objp->date_start,$objp->date_end); print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on if ($conf->global->FORM_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { - print '
'.nl2br(stripslashes($objp->product_desc)); + print '
'.nl2br($objp->product_desc); } print '';
'.$langs->trans('Note').'
'.$langs->trans("CloseAs").''; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 4ce0023dc73..d5005c74a06 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -88,8 +88,11 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $datelivraison = @mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']); $commande = new Commande($db); + $commande->socidp=$_POST['socidp']; + $commande->fetch_client(); + + $db->begin(); - $commande->socidp = $_POST['socidp']; $commande->date_commande = $datecommande; $commande->note = $_POST['note']; $commande->source = $_POST['source_id']; @@ -104,8 +107,6 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $commande->adresse_livraison_id = $_POST['adresse_livraison_id']; $commande->contactid = $_POST['contactidp']; - $commande->fetch_client(); - $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']); $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']); $commande->add_product($_POST['idprod3'],$_POST['qty3'],$_POST['remise_percent3']); @@ -117,13 +118,7 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $commande_id = $commande->create($user); - if ($commande_id <= 0) - { - $_GET['action']='create'; - $_GET['socidp']=$_POST['socidp']; - $mesg='
'.$commande->error.'
'; - } - else + if ($commande_id > 0) { // Insertion contact par defaut si défini if ($_POST["contactidp"]) @@ -144,6 +139,20 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $_GET['id'] = $commande->id; $action = ''; } + + // Fin création facture, on l'affiche + if ($commande_id > 0 && ! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + $_GET["action"]='create'; + $_GET['socidp']=$_POST['socidp']; + if (! $mesg) $mesg='
'.$commande->error.'
'; + } + } // Positionne ref commande client @@ -270,6 +279,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) // La description de la ligne est celle saisie ou // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini) + // \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on $desc=$_POST['np_desc']; if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC) { @@ -677,7 +687,7 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) // Reference client print '
'.$langs->trans('RefCustomer').''; print '
'; @@ -1551,7 +1562,7 @@ else $var=true; print '
'; if($soc->tva_assuj == "0") print '0'; @@ -1580,7 +1591,7 @@ else else $html->select_produits('','idprod','',$conf->produit->limit_size); if (! $conf->use_ajax) print '
'; - print ''; + print ''; print '