From f37af21107b08b57b118c6f1616bd1418c62363c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 4 Sep 2005 13:22:50 +0000 Subject: [PATCH] Meilleure gestion erreur --- htdocs/contrat/fiche.php | 801 ++++++++++++++++++++------------------- 1 file changed, 403 insertions(+), 398 deletions(-) diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 6c696c2cb7d..d256ccd09b8 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -458,432 +458,437 @@ else if ($id > 0) { $contrat = New Contrat($db); - if ( $contrat->fetch($id) > 0) + $result=$contrat->fetch($id); + if ($result <= 0) { + dolibarr_print_error($db); + exit; + } + + if ($mesg) print $mesg; + + $author = new User($db); + $author->id = $contrat->user_author_id; + $author->fetch(); + + $commercial_signature = new User($db); + $commercial_signature->id = $contrat->commercial_signature_id; + $commercial_signature->fetch(); - if ($mesg) print $mesg; - - $author = new User($db); - $author->id = $contrat->user_author_id; - $author->fetch(); - - $commercial_signature = new User($db); - $commercial_signature->id = $contrat->commercial_signature_id; - $commercial_signature->fetch(); + $commercial_suivi = new User($db); + $commercial_suivi->id = $contrat->commercial_suivi_id; + $commercial_suivi->fetch(); - $commercial_suivi = new User($db); - $commercial_suivi->id = $contrat->commercial_suivi_id; - $commercial_suivi->fetch(); + $h = 0; + $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id; + $head[$h][1] = $langs->trans("ContractCard"); + $hselected = $h; + $h++; - $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/contrat/fiche.php?id='.$contrat->id; - $head[$h][1] = $langs->trans("ContractCard"); - $hselected = $h; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id; + $head[$h][1] = $langs->trans("ContractContacts"); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id; + $head[$h][1] = $langs->trans("Info"); + $h++; - $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$contrat->id; - $head[$h][1] = $langs->trans("ContractContacts"); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/contrat/info.php?id='.$contrat->id; - $head[$h][1] = $langs->trans("Info"); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id); + dolibarr_fiche_head($head, $hselected, $langs->trans("Contract").': '.$contrat->id); - /* - * Confirmation de la suppression du contrat - */ - if ($_GET["action"] == 'delete') + /* + * Confirmation de la suppression du contrat + */ + if ($_GET["action"] == 'delete') + { + $html->form_confirm("fiche.php?id=$id",$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete"); + print '
'; + } + + /* + * Confirmation de la validation + */ + if ($_GET["action"] == 'valid') + { + //$numfa = contrat_get_num($soc); + $html->form_confirm("fiche.php?id=$id",$langs->trans("ValidateAContract"),$langs->trans("ConfirmValidateContract"),"confirm_valid"); + print '
'; + } + + /* + * Confirmation de la fermeture + */ + if ($_GET["action"] == 'close') + { + $html->form_confirm("fiche.php?id=$id",$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close"); + print '
'; + } + + /* + * Contrat + */ + if ($contrat->brouillon == 1 && $user->rights->contrat->creer) + { + print '
'; + print ''; + } + + print ''; + + // Reference du contrat + print '"; + + // Customer + print ""; + print ''; + + // Statut contrat + print '"; + + // Date + print ''; + print '\n"; + + // Factures associées + /* + TODO + */ + + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print '"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $var=false; + + print ''; + print ''; + print ''; + print ''; + + print ""; + print ''; + + print ''; + print ''; + print ''; + + print ""; + print ''; + print ''; + + print ''; + + $var=!$var; + + print ''; + print ''; + print ''; + print ''; + + print ""; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''."\n"; + + print ""; + print ''; + print ''; + + print ''; + } + print "
'.$langs->trans("Ref").''; + print $contrat->ref; + print "
".$langs->trans("Customer")."'; + print ''.$contrat->societe->nom.'
'.$langs->trans("Status").''; + print $contrat->statuts[$contrat->statut]; + print "
'.$langs->trans("Date").''.dolibarr_print_date($contrat->date_contrat,"%A %d %B %Y")."
'; + print ''; + if ($_GET["action"] != "classer") print ''; + print '
'; + print $langs->trans("Project"); + print ''.img_edit($langs->trans("SetProject")).'
'; + print '
'; + if ($_GET["action"] == "classer") { - $html->form_confirm("fiche.php?id=$id",$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete"); - print '
'; - } - - /* - * Confirmation de la validation - */ - if ($_GET["action"] == 'valid') - { - //$numfa = contrat_get_num($soc); - $html->form_confirm("fiche.php?id=$id",$langs->trans("ValidateAContract"),$langs->trans("ConfirmValidateContract"),"confirm_valid"); - print '
'; - } - - /* - * Confirmation de la fermeture - */ - if ($_GET["action"] == 'close') - { - $html->form_confirm("fiche.php?id=$id",$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close"); - print '
'; - } - - /* - * Contrat - */ - if ($contrat->brouillon == 1 && $user->rights->contrat->creer) - { - print ''; - print ''; - } - - print ''; - - // Reference du contrat - print '"; - - // Customer - print ""; - print ''; - - // Statut contrat - print '"; - - // Date - print ''; - print '\n"; - - // Factures associées - /* - TODO - */ - - // Projet - if ($conf->projet->enabled) - { - $langs->load("projects"); - print '"; - } - - print ''; - print ''; - print "
'.$langs->trans("Ref").''; - print $contrat->ref; - print "
".$langs->trans("Customer")."'; - print ''.$contrat->societe->nom.'
'.$langs->trans("Status").''; - print $contrat->statuts[$contrat->statut]; - print "
'.$langs->trans("Date").''.dolibarr_print_date($contrat->date_contrat,"%A %d %B %Y")."
'; - print ''; - if ($_GET["action"] != "classer") print ''; - print '
'; - print $langs->trans("Project"); - print ''.img_edit($langs->trans("SetProject")).'
'; - print '
'; - if ($_GET["action"] == "classer") - { - $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"projetid"); - } - else - { - $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"none"); - } - print "
'.$langs->trans("SalesRepresentativeFollowUp").''.$commercial_suivi->fullname.''.$langs->trans("SalesRepresentativeSignature").''.$commercial_signature->fullname.'
"; - - if ($contrat->brouillon == 1 && $user->rights->contrat->creer) - { - print ''; - } - - /* - * Lignes de contrats - */ - echo '
'; - - $sql = "SELECT cd.statut, cd.label, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid, cd.tva_tx, cd.remise_percent, cd.subprice,"; - $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,"; - $sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; - $sql.= " WHERE cd.fk_contrat = ".$id; - $sql.= " ORDER BY cd .rowid"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $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($result); - - $var=!$var; - - if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) - { - - print ''; - if ($objp->fk_product > 0) - { - print ''; - } - else - { - print "\n"; - } - // TVA - print ''; - // Prix - print '\n"; - // Quantité - print ''; - // Remise - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé) - print ''; - - // Statut - print ''; - - print "\n"; - - // Dates mise en service - print ''; - print ''; - print ''; - } - - // Ligne en mode update - else - { - print ""; - print ''; - print ''; - // Ligne carac - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - // Ligne dates prévues - print ""; - print ''; - print ''; - - print "\n"; - } - $i++; - } - $db->free($result); + $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"projetid"); } else { - dolibarr_print_error($db); + $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"none"); } + print ""; + } + print ''; + print ''; + print "
'.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").' '.$langs->trans("Status").'
'; - print ''; - print img_object($langs->trans("ShowService"),"service").' '.$objp->label.''; - if ($objp->description) print '
'.stripslashes(nl2br($objp->description)); - print '
".stripslashes(nl2br($objp->description))."'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '; - if ($contrat->statut != 2 && $user->rights->contrat->creer) - { - print ''; - print img_edit(); - print ''; - } - else { - print ' '; - } - if ($contrat->statut == 0 && $user->rights->contrat->creer) - { - print ' '; - print ''; - print img_delete(); - print ''; - } - print ''; - if ($contrat->statut > 0) print '';; - print img_statut($objp->statut); - if ($contrat->statut > 0) print ''; - print '
'; - // Si pas encore activé - if (! $objp->date_debut_reelle) { - print $langs->trans("DateStartPlanned").': '; - if ($objp->date_debut) print dolibarr_print_date($objp->date_debut); - else print $langs->trans("Unknown"); - } - // Si activé - if ($objp->date_debut_reelle) { - print $langs->trans("DateStartReal").': '; - if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle); - else print $langs->trans("ContractStatusNotRunning"); - } - - print '  -  '; - - // Si pas encore activé - if (! $objp->date_debut_reelle) { - print $langs->trans("DateEndPlanned").': '; - if ($objp->date_fin) { - print dolibarr_print_date($objp->date_fin); - } - else print $langs->trans("Unknown"); - } - // Si activé - if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { - print $langs->trans("DateEndPlanned").': '; - if ($objp->date_fin) { - print dolibarr_print_date($objp->date_fin); - if ($objp->date_fin < time()) { print " ".img_warning($langs->trans("Late")); } - } - else print $langs->trans("Unknown"); - } - // Si désactivé - if ($objp->date_debut_reelle && $objp->date_fin_reelle) { - print $langs->trans("DateEndReal").': '; - print dolibarr_print_date($objp->date_fin_reelle); - } - print '
'; - print ''; - if ($objp->label) - { - print img_object($langs->trans("ShowService"),"service").' '.$objp->label.'
'; - } - print '
'; - print $html->select_tva("eltva_tx",$objp->tva_tx); - print '%
'; - print $langs->trans("DateStartPlanned").' '; - $html->select_date($objp->date_debut,"date_start_update",0,0,($objp->date_debut>0?0:1)); - print '   '.$langs->trans("DateEndPlanned").' '; - $html->select_date($objp->date_fin,"date_end_update",0,0,($objp->date_fin>0?0:1)); - print '
'.$langs->trans("SalesRepresentativeFollowUp").''.$commercial_suivi->fullname.''.$langs->trans("SalesRepresentativeSignature").''.$commercial_signature->fullname.'
"; - /* - * Ajouter une ligne produit/service - */ - if ($user->rights->contrat->creer && $contrat->statut == 0) + if ($contrat->brouillon == 1 && $user->rights->contrat->creer) + { + print ''; + } + + /* + * Lignes de contrats + */ + echo '
'; + + $sql = "SELECT cd.statut, cd.label, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid, cd.tva_tx, cd.remise_percent, cd.subprice,"; + $sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,"; + $sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle"; + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; + $sql.= " WHERE cd.fk_contrat = ".$id; + $sql.= " ORDER BY cd .rowid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; $total = 0; + + if ($num) { - print ""; + print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print "\n"; - - $var=false; - - print ''; - print ''; - print ''; - print ''; - - print ""; - print ''; - - print ''; - print ''; - print ''; - - print ""; - print ''; - print ''; - - print ''; + } + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($result); $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print ""; - print ''; + if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid) + { - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + if ($objp->fk_product > 0) + { + print ''; + } + else + { + print "\n"; + } + // TVA + print ''; + // Prix + print '\n"; + // Quantité + print ''; + // Remise + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + // Icon update et delete (statut contrat 0=brouillon,1=validé,2=fermé) + print ''; + + // Statut + print ''; - print ''."\n"; + print "\n"; - print ""; - print ''; - print ''; - - print ''; + // Dates mise en service + print ''; + print ''; + print ''; + } + + // Ligne en mode update + else + { + print ""; + print ''; + print ''; + // Ligne carac + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // Ligne dates prévues + print ""; + print ''; + print ''; + + print "\n"; + } + $i++; } - print "
'.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'  '.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").' '.$langs->trans("Status").'
'; - $html->select_produits('','p_idprod','',0); - print '%
'; - print $langs->trans("DateStartPlanned").' '; - $html->select_date('',"date_start",0,0,1); - print '   '.$langs->trans("DateEndPlanned").' '; - $html->select_date('',"date_end",0,0,1); - print '
'; - $html->select_tva("tva_tx",$conf->defaulttx); - print '%
'; + print ''; + print img_object($langs->trans("ShowService"),"service").' '.$objp->label.''; + if ($objp->description) print '
'.stripslashes(nl2br($objp->description)); + print '
".stripslashes(nl2br($objp->description))."'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '; + if ($contrat->statut != 2 && $user->rights->contrat->creer) + { + print ''; + print img_edit(); + print ''; + } + else { + print ' '; + } + if ($contrat->statut == 0 && $user->rights->contrat->creer) + { + print ' '; + print ''; + print img_delete(); + print ''; + } + print ''; + if ($contrat->statut > 0) print '';; + print img_statut($objp->statut); + if ($contrat->statut > 0) print ''; + print '
'; - print $langs->trans("DateStartPlanned").' '; - $html->select_date('',"date_start",0,0,1); - print '   '.$langs->trans("DateEndPlanned").' '; - $html->select_date('',"date_end",0,0,1); - print '
'; + // Si pas encore activé + if (! $objp->date_debut_reelle) { + print $langs->trans("DateStartPlanned").': '; + if ($objp->date_debut) print dolibarr_print_date($objp->date_debut); + else print $langs->trans("Unknown"); + } + // Si activé + if ($objp->date_debut_reelle) { + print $langs->trans("DateStartReal").': '; + if ($objp->date_debut_reelle) print dolibarr_print_date($objp->date_debut_reelle); + else print $langs->trans("ContractStatusNotRunning"); + } + + print '  -  '; + + // Si pas encore activé + if (! $objp->date_debut_reelle) { + print $langs->trans("DateEndPlanned").': '; + if ($objp->date_fin) { + print dolibarr_print_date($objp->date_fin); + } + else print $langs->trans("Unknown"); + } + // Si activé + if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { + print $langs->trans("DateEndPlanned").': '; + if ($objp->date_fin) { + print dolibarr_print_date($objp->date_fin); + if ($objp->date_fin < time()) { print " ".img_warning($langs->trans("Late")); } + } + else print $langs->trans("Unknown"); + } + // Si désactivé + if ($objp->date_debut_reelle && $objp->date_fin_reelle) { + print $langs->trans("DateEndReal").': '; + print dolibarr_print_date($objp->date_fin_reelle); + } + print '
'; + print ''; + if ($objp->label) + { + print img_object($langs->trans("ShowService"),"service").' '.$objp->label.'
'; + } + print '
'; + print $html->select_tva("eltva_tx",$objp->tva_tx); + print '%
'; + print $langs->trans("DateStartPlanned").' '; + $html->select_date($objp->date_debut,"date_start_update",0,0,($objp->date_debut>0?0:1)); + print '   '.$langs->trans("DateEndPlanned").' '; + $html->select_date($objp->date_fin,"date_end_update",0,0,($objp->date_fin>0?0:1)); + print '
"; - /* - * Fin Ajout ligne - */ - - print ''; - - /************************************************************* - * Boutons Actions - *************************************************************/ - - if ($user->societe_id == 0) - { - print '
'; - - if ($contrat->statut == 0 && $num) - { - print ''.$langs->trans("Validate").''; - } - - $numclos=$contrat->array_detail(5); // Tableau des lignes au statut clos - if ($contrat->statut == 1 && $num == sizeof($numclos)) - { - print ''.$langs->trans("Close").''; - } - - if ($contrat->statut == 0 && $user->rights->contrat->supprimer) - { - print ''.$langs->trans("Delete").''; - } - - print "
"; - } - + $db->free($result); } else { - // Contrat non trouvé - print "Contrat inexistant ou accés refusé"; + dolibarr_print_error($db); } + + + /* + * Ajouter une ligne produit/service + */ + if ($user->rights->contrat->creer && $contrat->statut == 0) + { + print "
'.$langs->trans("Service").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'  
'; + $html->select_produits('','p_idprod','',0); + print '%
'; + print $langs->trans("DateStartPlanned").' '; + $html->select_date('',"date_start",0,0,1); + print '   '.$langs->trans("DateEndPlanned").' '; + $html->select_date('',"date_end",0,0,1); + print '
'; + $html->select_tva("tva_tx",$conf->defaulttx); + print '%
'; + print $langs->trans("DateStartPlanned").' '; + $html->select_date('',"date_start",0,0,1); + print '   '.$langs->trans("DateEndPlanned").' '; + $html->select_date('',"date_end",0,0,1); + print '
"; + /* + * Fin Ajout ligne + */ + + print ''; + + + /************************************************************* + * Boutons Actions + *************************************************************/ + + if ($user->societe_id == 0) + { + print '
'; + + if ($contrat->statut == 0 && $num) + { + print ''.$langs->trans("Validate").''; + } + + if ($contrat->statut > 0 && $user->rights->facture->creer) + { + $langs->load("bills"); + print ''.$langs->trans("CreateBill").''; + } + + $numclos=$contrat->array_detail(5); // Tableau des lignes au statut clos + if ($contrat->statut == 1 && $num == sizeof($numclos)) + { + print ''.$langs->trans("Close").''; + } + + if ($contrat->statut == 0 && $user->rights->contrat->supprimer) + { + print ''.$langs->trans("Delete").''; + } + + print "
"; + } + } }