From ea835c93c1236af22d9e52c6b0571fa66fbbfac9 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 2 Aug 2005 07:23:45 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20possibilit=E9=20de=20modifier=20une=20l?= =?UTF-8?q?igne=20de=20propale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/propal.php | 1918 ++++++++++++++++++++------------------- htdocs/propal.class.php | 639 +++++++------ 2 files changed, 1319 insertions(+), 1238 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 7aee38a1e9e..942625ff01b 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Marc Barilley / Ocebo @@ -71,67 +71,67 @@ $form=new Form($db); if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') { - if ($user->rights->propale->supprimer) - { - $propal = new Propal($db, 0, $_GET['propalid']); - $propal->delete($user); - $propalid = 0; - $brouillon = 1; - } - Header('Location: propal.php'); + if ($user->rights->propale->supprimer) + { + $propal = new Propal($db, 0, $_GET['propalid']); + $propal->delete($user); + $propalid = 0; + $brouillon = 1; + } + Header('Location: propal.php'); } if ($_POST['action'] == 'add') { - $propal = new Propal($db, $_GET['socidp']); - $propal->datep = mktime(12, 1 , 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - - $propal->duree_validite = $_POST['duree_validite']; - - $propal->contactid = $_POST['contactidp']; - $propal->projetidp = $_POST['projetidp']; - $propal->modelpdf = $_POST['modelpdf']; - $propal->author = $user->id; - $propal->note = $_POST['note']; - - $propal->ref = $_POST['ref']; - - for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) - { - $xid = 'idprod'.$i; - $xqty = 'qty'.$i; - $xremise = 'remise'.$i; - $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); - } - - $id = $propal->create(); - - /* - * Generation - */ - if ($id) - { - propale_pdf_create($db, $id, $_POST['modelpdf']); - Header ('Location: propal.php?propalid='.$id); - } + $propal = new Propal($db, $_GET['socidp']); + $propal->datep = mktime(12, 1 , 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + + $propal->duree_validite = $_POST['duree_validite']; + + $propal->contactid = $_POST['contactidp']; + $propal->projetidp = $_POST['projetidp']; + $propal->modelpdf = $_POST['modelpdf']; + $propal->author = $user->id; + $propal->note = $_POST['note']; + + $propal->ref = $_POST['ref']; + + for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) + { + $xid = 'idprod'.$i; + $xqty = 'qty'.$i; + $xremise = 'remise'.$i; + $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); + } + + $id = $propal->create(); + + /* + * Generation + */ + if ($id) + { + propale_pdf_create($db, $id, $_POST['modelpdf']); + Header ('Location: propal.php?propalid='.$id); + } } if ($_GET['action'] == 'pdf') { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); } if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer) { - /* - * Cloture de la propale - */ - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->cloture($user, $_POST['statut'], $_POST['note']); + /* + * Cloture de la propale + */ + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->cloture($user, $_POST['statut'], $_POST['note']); } /* @@ -140,219 +140,233 @@ if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer) */ if ($_POST['action'] == 'send') { - $langs->load('mails'); - $propal= new Propal($db); - if ( $propal->fetch($_POST['propalid']) ) + $langs->load('mails'); + $propal= new Propal($db); + if ( $propal->fetch($_POST['propalid']) ) + { + $propalref = sanitize_string($propal->ref); + $file = $conf->propal->dir_output . '/' . $propalref . '/' . $propalref . '.pdf'; + if (is_readable($file)) { - $propalref = sanitize_string($propal->ref); - $file = $conf->propal->dir_output . '/' . $propalref . '/' . $propalref . '.pdf'; - if (is_readable($file)) - { - $soc = new Societe($db, $propal->socidp); - if ($_POST['sendto']) - { - // Le destinataire a été fourni via le champ libre - $sendto = $_POST['sendto']; - $sendtoid = 0; - } - elseif ($_POST['receiver']) - { - // Le destinataire a été fourni via la liste déroulante - $sendto = $soc->contact_get_email($_POST['receiver']); - $sendtoid = $_POST['receiver']; - } + $soc = new Societe($db, $propal->socidp); + if ($_POST['sendto']) + { + // Le destinataire a été fourni via le champ libre + $sendto = $_POST['sendto']; + $sendtoid = 0; + } + elseif ($_POST['receiver']) + { + // Le destinataire a été fourni via la liste déroulante + $sendto = $soc->contact_get_email($_POST['receiver']); + $sendtoid = $_POST['receiver']; + } - if (strlen($sendto)) - { - $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; - $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; - $message = $_POST['message']; - if ($_POST['action'] == 'send') - { - $subject = $langs->trans('Propal').' '.$propal->ref; - $actiontypeid=3; - $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.
'; - if ($message) - { - $actionmsg.='Texte utilisé dans le corps du message:
'; - $actionmsg.=$message; - } - $actionmsg2='Envoi Propal par mail'; - } - /* - if ($_POST["action"] == 'relance') - { - $subject = "Relance facture $propal->ref"; - $actiontypeid=10; - $actionmsg="Mail envoyé par $from à $sendto.
"; - if ($message) - { - $actionmsg.="Texte utilisé dans le corps du message:
"; - $actionmsg.=$message; - } - $actionmsg2="Relance Facture par mail"; - } - */ - $filepath[0] = $file; - $filename[0] = $propal->ref.'.pdf'; - $mimetype[0] = 'application/pdf'; - 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 - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc); - if ($mailfile->sendfile()) - { - $msg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; - // Insertion action - include_once('../contact.class.php'); - $actioncomm = new ActionComm($db); - $actioncomm->type_id = $actiontypeid; - $actioncomm->label = $actionmsg2; - $actioncomm->note = $actionmsg; - $actioncomm->date = time(); // L'action est faite maintenant - $actioncomm->percent = 100; - $actioncomm->contact = new Contact($db,$sendtoid); - $actioncomm->societe = new Societe($db,$propal->socidp); - $actioncomm->user = $user; // User qui a fait l'action - $actioncomm->propalrowid = $propal->id; - $ret=$actioncomm->add($user); // User qui saisi l'action - if ($ret < 0) - { - dolibarr_print_error($db); - } - else - { - // Renvoie sur la fiche - Header('Location: propal.php?propalid='.$propal->id.'&msg='.urlencode($msg)); - exit; - } - } - else - { - $msg='
'.$langs->trans('ErrorFailedToSendMail',$from,$sendto).' - '.$actioncomm->error.'
'; - } - } - else - { - $msg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; - dolibarr_syslog('Le mail du destinataire est vide'); - } - } - else + if (strlen($sendto)) + { + $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; + $message = $_POST['message']; + if ($_POST['action'] == 'send') { - dolibarr_syslog('Impossible de lire :'.$file); + $subject = $langs->trans('Propal').' '.$propal->ref; + $actiontypeid=3; + $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.
'; + if ($message) + { + $actionmsg.='Texte utilisé dans le corps du message:
'; + $actionmsg.=$message; + } + $actionmsg2='Envoi Propal par mail'; } + /* + if ($_POST["action"] == 'relance') + { + $subject = "Relance facture $propal->ref"; + $actiontypeid=10; + $actionmsg="Mail envoyé par $from à $sendto.
"; + if ($message) + { + $actionmsg.="Texte utilisé dans le corps du message:
"; + $actionmsg.=$message; + } + $actionmsg2="Relance Facture par mail"; + } + */ + $filepath[0] = $file; + $filename[0] = $propal->ref.'.pdf'; + $mimetype[0] = 'application/pdf'; + 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 + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc); + if ($mailfile->sendfile()) + { + $msg='
'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.
'; + // Insertion action + include_once('../contact.class.php'); + $actioncomm = new ActionComm($db); + $actioncomm->type_id = $actiontypeid; + $actioncomm->label = $actionmsg2; + $actioncomm->note = $actionmsg; + $actioncomm->date = time(); // L'action est faite maintenant + $actioncomm->percent = 100; + $actioncomm->contact = new Contact($db,$sendtoid); + $actioncomm->societe = new Societe($db,$propal->socidp); + $actioncomm->user = $user; // User qui a fait l'action + $actioncomm->propalrowid = $propal->id; + $ret=$actioncomm->add($user); // User qui saisi l'action + if ($ret < 0) + { + dolibarr_print_error($db); + } + else + { + // Renvoie sur la fiche + Header('Location: propal.php?propalid='.$propal->id.'&msg='.urlencode($msg)); + exit; + } + } + else + { + $msg='
'.$langs->trans('ErrorFailedToSendMail',$from,$sendto).' - '.$actioncomm->error.'
'; + } + } + else + { + $msg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; + dolibarr_syslog('Le mail du destinataire est vide'); + } } - else + else { - dolibarr_syslog('Impossible de lire les données de la propale. Le fichier propal n\'a peut-être pas été généré.'); + dolibarr_syslog('Impossible de lire :'.$file); } + } + else + { + dolibarr_syslog('Impossible de lire les données de la propale. Le fichier propal n\'a peut-être pas été généré.'); + } } if ($_GET['action'] == 'commande') { - /* - * Cloture de la propale - */ - $propal = new Propal($db); - $propal->fetch($propalid); - $propal->create_commande($user); + /* + * Cloture de la propale + */ + $propal = new Propal($db); + $propal->fetch($propalid); + $propal->create_commande($user); } if ($_GET['action'] == 'modif' && $user->rights->propale->creer) { - /* - * Repasse la propale en mode brouillon - */ - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->reopen($user->id); + /* + * Repasse la propale en mode brouillon + */ + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->reopen($user->id); } if ($_POST['addligne'] == $langs->trans('Add') && $user->rights->propale->creer) { - /* - * Ajout d'une ligne produit dans la propale - */ - if ($_POST['idprod']) - { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->insert_product($_POST['idprod'], $_POST['qty'], $_POST['remise']); - propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); - } + /* + * Ajout d'une ligne produit dans la propale + */ + if ($_POST['idprod']) + { + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->insert_product($_POST['idprod'], $_POST['qty'], $_POST['remise']); + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); + } +} + +if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer) +{ + /* + * Mise à jour d'une ligne dans la propale + */ + + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->UpdateLigne($_POST['ligne'], $_POST['subprice'], $_POST['qty'], $_POST['remise']); + + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); } if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->creer) { - /* - * Ajout d'une ligne produit dans la propale - */ - if (strlen($_POST['np_desc']) && strlen($_POST['np_price'])) - { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->insert_product_generic( - $_POST['np_desc'], - $_POST['np_price'], - $_POST['np_qty'], - $_POST['np_tva_tx'], - $_POST['np_remise']); - } + /* + * Ajout d'une ligne produit dans la propale + */ + if (strlen($_POST['np_desc']) && strlen($_POST['np_price'])) + { + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->insert_product_generic( + $_POST['np_desc'], + $_POST['np_price'], + $_POST['np_qty'], + $_POST['np_tva_tx'], + $_POST['np_remise']); + } } -if ($_POST['action'] == 'setremise' && $user->rights->propale->creer) -{ - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->set_remise($user, $_POST['remise']); - propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); -} if ($_POST['action'] == 'setpdfmodel' && $user->rights->propale->creer) { - $propal = new Propal($db, 0, $_GET['propalid']); - $propal->set_pdf_model($user, $_POST['modelpdf']); - propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']); + $propal = new Propal($db, 0, $_GET['propalid']); + $propal->set_pdf_model($user, $_POST['modelpdf']); + propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']); } if ($_GET['action'] == 'del_ligne' && $user->rights->propale->creer) { - /* - * Supprime une ligne produit dans la propale - */ - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->delete_product($_GET['ligne']); - propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); + /* + * Supprime une ligne produit dans la propale + */ + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->delete_product($_GET['ligne']); + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); } if ($_GET['valid'] == 1 && $user->rights->propale->valider) { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->update_price($_GET['propalid']); - propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); - $propal->valid($user); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->update_price($_GET['propalid']); + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); + $propal->valid($user); +} + +if ($_POST['action'] == 'setremise' && $user->rights->propale->creer) +{ + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->set_remise($user, $_POST['remise']); + propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf); } if ($_POST['action'] == 'set_project') { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->set_project($user, $_POST['projetidp']); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->set_project($user, $_POST['projetidp']); } if ($_POST['action'] == 'set_contact') { - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); - $propal->set_contact($user, $_POST['contactidp']); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + $propal->set_contact($user, $_POST['contactidp']); } @@ -365,804 +379,820 @@ llxHeader(); */ if ($_GET['propalid']) { - if ($msg) print "$msg
"; - $html = new Form($db); + if ($msg) print "$msg
"; + $html = new Form($db); - $propal = new Propal($db); - $propal->fetch($_GET['propalid']); + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); - $societe = new Societe($db); - $societe->fetch($propal->soc_id); - $h=0; + $societe = new Societe($db); + $societe->fetch($propal->soc_id); + $h=0; - $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('CommercialCard'); - $hselected=$h; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('CommercialCard'); + $hselected=$h; + $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('AccountancyCard'); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('AccountancyCard'); + $h++; - $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('Note'); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('Note'); + $h++; - $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('Info'); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('Info'); + $h++; - $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('Documents'); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('Documents'); + $h++; - dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref); + dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref); - /* - * Confirmation de la suppression de la propale - * - */ - if ($_GET['action'] == 'delete') + /* + * Confirmation de la suppression de la propale + * + */ + if ($_GET['action'] == 'delete') + { + $html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete'); + print '
'; + } + + + /* + * Fiche propal + * + */ + $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,'; + $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'socpeople as x'; + $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_soc_contact = x.idp AND p.rowid = '.$propal->id; + if ($socidp) $sql .= ' AND s.idp = '.$socidp; + + $result = $db->query($sql); + if ($result) + { + if ($db->num_rows($result)) { - $html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete'); - print '
'; - } + $obj = $db->fetch_object($result); + $societe = new Societe($db); + $societe->fetch($obj->idp); - /* - * Fiche propal - * - */ - $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,'; - $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'socpeople as x'; - $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_soc_contact = x.idp AND p.rowid = '.$propal->id; - if ($socidp) $sql .= ' AND s.idp = '.$socidp; + print ''; + $rowspan=6; + print ''; + print ''; + print ''; + print ''; - $result = $db->query($sql); - if ($result) - { - if ($db->num_rows($result)) + print ''; + + print ''; + print ''; + + // Destinataire + $langs->load('mails'); + print ''; + print ''; + + $dests=$societe->contact_array($societe->id); + $numdest = count($dests); + if ($numdest==0) + { + print ''; + } + else + { + if ($propal->statut == 0 && $user->rights->propale->creer) { - $obj = $db->fetch_object($result); - - $societe = new Societe($db); - $societe->fetch($obj->idp); - - print '
'.$langs->trans('Company').''; + if ($societe->client == 1) + { + $url ='fiche.php?socid='.$societe->id; + } + else + { + $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$societe->id; + } + print ''.$societe->nom.'Conditions de réglement'.' '.'
'.$langs->trans('Date').''; + print dolibarr_print_date($propal->date,'%a %e %B %Y'); + print ''.$langs->trans('DateEndPropal').''; + if ($propal->fin_validite) + { + print dolibarr_print_date($propal->fin_validite); + } + else { + print $langs->trans("Unknown"); + } + print '
'.$langs->trans('MailTo').''; + print 'Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale
'; + print ''.$langs->trans('AddContact').''; + print '
'; - $rowspan=6; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - - // Destinataire - $langs->load('mails'); - print ''; - print ''; - - $dests=$societe->contact_array($societe->id); - $numdest = count($dests); - if ($numdest==0) - { - print ''; - } - else - { - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - } - else - { - if (!empty($propal->contactid)) - { - print ''; - } - else { - print ''; - } - } - } - print ''; - - if ($conf->projet->enabled) - $rowspan++; - - print ''; - - if ($conf->projet->enabled) - { - print ''; - $langs->load('projects'); - $numprojet = $societe->has_projects(); - if (! $numprojet) - { - print ''; - } - else - { - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - } - else - { - if (!empty($propal->projetidp)) - { - print ''; - } - else { - print ''; - } - } - } - print ''; - } - - print ''; - if ($propal->brouillon == 1 && $user->rights->propale->creer) - { - print ''; - print ''; - print ''; - print ''; - } - else - { - print ''; - } - print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print '
'.$langs->trans('Company').''; - if ($societe->client == 1) - { - $url ='fiche.php?socid='.$societe->id; - } - else - { - $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$societe->id; - } - print ''.$societe->nom.'Conditions de réglement'.' '.'
'.$langs->trans('Date').''; - print dolibarr_print_date($propal->date); - print ''.$langs->trans('DateEndPropal').''; - if ($propal->fin_validite) - { - print dolibarr_print_date($propal->fin_validite); - } - else { - print $langs->trans("Unknown"); - } - print '
'.$langs->trans('MailTo').''; - print 'Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale
'; - print ''.$langs->trans('AddContact').''; - print '
'; - print '
'; - print ''; - $form->select_contacts($societe->id, $propal->contactid, 'contactidp'); - print '
'; - print ''; - print ''; - print ''; - require_once(DOL_DOCUMENT_ROOT.'/contact.class.php'); - $contact=new Contact($db); - $contact->fetch($propal->contactid); - print ''; - print $contact->firstname.' '.$contact->name; - print ''; - print ' '.$langs->trans('Note').' :
'. nl2br($propal->note).'
'.$langs->trans('Project').''; - print $langs->trans("NoProject").''; - print 'id.'&action=create>'.$langs->trans('AddProject').''; - print ''; - print '
'; - print ''; - $form->select_projects($societe->id, $propal->projetidp, 'projetidp'); - print '
'; - print ''; - print ''; - print ''; - $proj = new Project($db); - $proj->fetch($propal->projetidp); - print ''; - print $proj->title; - print ''; - print ' 
'.$langs->trans('GlobalDiscount').'
% '; - print ''; - print ''; - print ' ?'; - print ''.$propal->remise_percent.'%
'.$langs->trans('AmountHT').''.price($obj->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('VAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut().'

'; - if ($propal->brouillon == 1 && $user->rights->propale->creer) - { - print ''; - } - - /* - * Lignes de propale - * - */ - $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; - $sql .= ' WHERE pt.fk_propal = '.$propal->id; - $sql .= ' ORDER BY pt.rowid ASC'; - $result = $db->query($sql); - if ($result) - { - $num_lignes = $db->num_rows($result); - $i = 0; - $total = 0; - - print ''; - if ($num_lignes) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=True; - while ($i < $num_lignes) - { - $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"; - } - print ''; - print '\n"; - print ''; - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - print '\n"; - - // Icone d'edition et suppression - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - print ''; - } - else - { - print ''; - } - print ''; - } - // Update ligne de propal - // \todo - - - $total = $total + ($objp->qty * $objp->price); - $i++; - } - $db->free($result); - } - else - { - dolibarr_print_error($db); - } - - /* - * Ajouter une ligne - * - */ - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; - print ''; - - // Ajout produit produits/services personalisés - $var=true; - print '\n"; - print ' '; - print ' \n"; - print ' '; - print ' '; - print ' '; - print ' '; - print ''; - - // Ajout de produits/services prédéfinis - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; - } - - print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'  
'; - if ($objp->fk_product_type) - print img_object($langs->trans('ShowService'),'service'); - else - print img_object($langs->trans('ShowProduct'),'product'); - print ' '.stripslashes(nl2br($objp->description?$objp->description:$objp->product)).''; - if ($objp->date_start && $objp->date_end) - { - print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; - } - if ($objp->date_start && ! $objp->date_end) - { - print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; - } - if (! $objp->date_start && $objp->date_end) - { - print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; - } - print ''.stripslashes(nl2br($objp->description)); - if ($objp->date_start && $objp->date_end) - { - print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; - } - if ($objp->date_start && ! $objp->date_end) - { - print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; - } - if (! $objp->date_start && $objp->date_end) - { - print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; - } - print "'.$objp->tva_tx.' %'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."'; - print img_edit(); - print ''; - print img_delete(); - print '  
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').'   
'; - print $html->select_tva('np_tva_tx', $conf->defaulttx) . " %
'; - $html->select_produits('','idprod','',20); - print '  %
'; - + print ''; + print '
'; + print ''; + $form->select_contacts($societe->id, $propal->contactid, 'contactidp'); + print ''; + print ''; + print '
'; + print ''; } - } - else - { - dolibarr_print_error($db); - } - - print ''; - - /* - * Formulaire cloture (signé ou non) - */ - if ($_GET['action'] == 'statut') - { - print '
'; - print ''; - print ''; - print '
'.$langs->trans("CloseAs").': '; - print ''; - print ''; - print '
'.$langs->trans('Note').':
'; - } - - - /* - * Barre d'actions - */ - if ($propal->statut < 2) - { - print '
'; - - // Valid - if ($propal->statut == 0) + else { - if ($user->rights->propale->valider) - { - print ''.$langs->trans('Valid').''; - } + if (!empty($propal->contactid)) + { + print ''; + require_once(DOL_DOCUMENT_ROOT.'/contact.class.php'); + $contact=new Contact($db); + $contact->fetch($propal->contactid); + print ''; + print $contact->firstname.' '.$contact->name; + print ''; + print ''; + } + else { + print ' '; + } } + } + print ''; - // Save - if ($propal->statut == 1) + if ($conf->projet->enabled) + $rowspan++; + + print ''.$langs->trans('Note').' :
'. nl2br($propal->note).''; + + if ($conf->projet->enabled) + { + print ''.$langs->trans('Project').''; + $langs->load('projects'); + $numprojet = $societe->has_projects(); + if (! $numprojet) { - if ($user->rights->propale->creer) - { - print ''.$langs->trans('Edit').''; - } + print ''; + print $langs->trans("NoProject").''; + print 'id.'&action=create>'.$langs->trans('AddProject').''; + print ''; } - - // Build PDF - if ($propal->statut < 2 && $user->rights->propale->creer) + else { - print ''.$langs->trans('BuildPDF').''; - } - - // Send - if ($propal->statut == 1) - { - if ($user->rights->propale->envoyer) + if ($propal->statut == 0 && $user->rights->propale->creer) + { + print ''; + print '
'; + print ''; + $form->select_projects($societe->id, $propal->projetidp, 'projetidp'); + print ''; + print ''; + print '
'; + print ''; + } + else + { + if (!empty($propal->projetidp)) { - $propref = sanitize_string($obj->ref); - $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; - if (file_exists($file)) - { - print ''.$langs->trans('Send').''; - } + print ''; + $proj = new Project($db); + $proj->fetch($propal->projetidp); + print ''; + print $proj->title; + print ''; + print ''; } + else { + print ' '; + } + } } + print ''; + } - // Close - if ($propal->statut != 0) + print ''.$langs->trans('GlobalDiscount').''; + if ($propal->brouillon == 1 && $user->rights->propale->creer) + { + print '
'; + print ''; + print '% '; + print ''; + print ''; + print ' ?'; + print ''; + print '
'; + } + else + { + print ''.$propal->remise_percent.'%'; + } + print ''; + + print ''.$langs->trans('AmountHT').''; + print ''.price($propal->price).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + + print ''.$langs->trans('VAT').''.price($propal->total_tva).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + print ''.$langs->trans('AmountTTC').''.price($propal->total_ttc).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + print ''.$langs->trans('Status').''.$propal->getLibStatut().''; + print '
'; + if ($propal->brouillon == 1 && $user->rights->propale->creer) + { + print ''; + } + + /* + * Lignes de propale + * + */ + $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; + $sql .= ' WHERE pt.fk_propal = '.$propal->id; + $sql .= ' ORDER BY pt.rowid ASC'; + $result = $db->query($sql); + if ($result) + { + $num_lignes = $db->num_rows($result); + $i = 0; + $total = 0; + + print ''; + if ($num_lignes) { - if ($propal->statut == 1 && $user->rights->propale->cloturer) - { - print ''.$langs->trans('Close').''; - } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; } - - // Delete - if ($propal->statut == 0) + $var=True; + while ($i < $num_lignes) { - if ($user->rights->propale->supprimer) + $objp = $db->fetch_object($result); + $var=!$var; + if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) + { + print ''; + if ($objp->fk_product > 0) { - print ''.$langs->trans('Delete').''; + print ''; } + else + { + print '\n"; + } + print ''; + print '\n"; + print ''; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + print '\n"; + + // Icone d'edition et suppression + if ($propal->statut == 0 && $user->rights->propale->creer) + { + print ''; + print ''; + } + else + { + print ''; + } + print ''; + } + // Update ligne de propal + // \todo + + if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] == 'editline' && $_GET["ligne"] == $objp->rowid) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + } + // + + $total = $total + ($objp->qty * $objp->price); + $i++; } + $db->free($result); + } + else + { + dolibarr_print_error($db); + } - print ''; + /* + * Ajouter une ligne + * + */ + if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline') + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ''; + print ''; + + // Ajout produit produits/services personalisés + $var=true; + print '\n"; + print ' '; + print ' \n"; + print ' '; + print ' '; + print ' '; + print ' '; + print ''; + + // Ajout de produits/services prédéfinis + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ''; + } + + print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'  
'; + if ($objp->fk_product_type) + print img_object($langs->trans('ShowService'),'service'); + else + print img_object($langs->trans('ShowProduct'),'product'); + print ' '.stripslashes(nl2br($objp->description?$objp->description:$objp->product)).''; + if ($objp->date_start && $objp->date_end) + { + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; + } + if ($objp->date_start && ! $objp->date_end) + { + print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; + } + if (! $objp->date_start && $objp->date_end) + { + print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + } + print ''.stripslashes(nl2br($objp->description)); + if ($objp->date_start && $objp->date_end) + { + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; + } + if ($objp->date_start && ! $objp->date_end) + { + print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; + } + if (! $objp->date_start && $objp->date_end) + { + print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + } + print "'.$objp->tva_tx.' %'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."'; + print img_edit(); + print ''; + print img_delete(); + print '  
  % 
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').'   
'; + print $html->select_tva('np_tva_tx', $conf->defaulttx) . " %
'; + $html->select_produits('','idprod','',20); + print '  %
'; + + } + } + else + { + dolibarr_print_error($db); + } + + print '
'; + + /* + * Formulaire cloture (signé ou non) + */ + if ($_GET['action'] == 'statut') + { + print '
'; + print ''; + print ''; + print '
'.$langs->trans("CloseAs").': '; + print ''; + print ''; + print '
'.$langs->trans('Note').':
'; + } + + + /* + * Barre d'actions + */ + if ($propal->statut < 2) + { + print '
'; + + // Valid + if ($propal->statut == 0) + { + if ($user->rights->propale->valider) + { + print ''.$langs->trans('Valid').''; + } } - - print '
'; - - /* - * Documents - */ - if ($propal->brouillon == 1) + // Save + if ($propal->statut == 1) { - print '
'; - print ''; - } - print_titre($langs->trans('Documents')); - - print ''; - $propref = sanitize_string($propal->ref); - $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; - $relativepath = $propref.'/'.$propref.'.pdf'; - - $var=true; - - if (file_exists($file)) - { - print ''; - print ''; - print ''; - print ''; + if ($user->rights->propale->creer) + { + print ''.$langs->trans('Edit').''; + } } - if ($propal->brouillon == 1 && $user->rights->propale->creer) + // Build PDF + if ($propal->statut < 2 && $user->rights->propale->creer) { - print ''; - } - print "
'.$langs->trans('Propal').' PDF'.$propal->ref.'.pdf'.filesize($file). ' bytes'.strftime('%d %B %Y %H:%M:%S',filemtime($file)).'
Modèle'; - $html = new Form($db); - $modelpdf = new Propal_Model_pdf($db); - $html->select_array('modelpdf',$modelpdf->liste_array(),$propal->modelpdf); - print ''; - print '
\n"; + print ''.$langs->trans('BuildPDF').''; + } - if ($propal->brouillon == 1) + // Send + if ($propal->statut == 1) { - print '
'; - } - - - /* - * Commandes rattachées - */ - if($conf->commande->enabled) - { - $coms = $propal->associated_orders(); - if (sizeof($coms) > 0) + if ($user->rights->propale->envoyer) + { + $propref = sanitize_string($obj->ref); + $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; + if (file_exists($file)) { - print '
'; - print_titre($langs->trans('RelatedOrders')); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=true; - for ($i = 0 ; $i < sizeof($coms) ; $i++) - { - $var=!$var; - print '\n"; - print ''; - print ''; - print "\n"; - } - print '
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'; - print ''.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."'.dolibarr_print_date($coms[$i]->date).''.$coms[$i]->total_ttc.'
'; + print ''.$langs->trans('Send').''; } + } } - print '
'; - - /* - * Liste des actions propres à la propal - */ - $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ; - $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; - $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ; - $result = $db->query($sql); - if ($result) + // Close + if ($propal->statut != 0) { - $num = $db->num_rows($result); - if ($num) - { - print_titre($langs->trans('ActionsOnPropal')); - $i = 0; - $total = 0; - $var=true; - - print ''; - print ''; - print "\n"; - - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ''; - print ''; - print '\n"; - print ''; - $authoract = new User($db); - $authoract->id = $objp->fk_user_author; - $authoract->fetch(''); - print ''; - print "\n"; - $i++; - } - print '
'.$langs->trans('Ref').''.$langs->trans('Date').''.$langs->trans('Action').''.$langs->trans('By').'
'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$authoract->code.'
'; - } + if ($propal->statut == 1 && $user->rights->propale->cloturer) + { + print ''.$langs->trans('Close').''; + } } - else + + // Delete + if ($propal->statut == 0) { - dolibarr_print_error($db); + if ($user->rights->propale->supprimer) + { + print ''.$langs->trans('Delete').''; + } } - print '
'; + print '
'; + } + print '
'; - /* - * Action presend - * - */ - if ($_GET['action'] == 'presend') + /* + * Documents + */ + if ($propal->brouillon == 1) + { + print '
'; + print ''; + } + print_titre($langs->trans('Documents')); + + print ''; + $propref = sanitize_string($propal->ref); + $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; + $relativepath = $propref.'/'.$propref.'.pdf'; + + $var=true; + + if (file_exists($file)) + { + print ''; + print ''; + print ''; + print ''; + } + + if ($propal->brouillon == 1 && $user->rights->propale->creer) + { + print ''; + } + print "
'.$langs->trans('Propal').' PDF'.$propal->ref.'.pdf'.filesize($file). ' bytes'.strftime('%d %B %Y %H:%M:%S',filemtime($file)).'
Modèle'; + $html = new Form($db); + $modelpdf = new Propal_Model_pdf($db); + $html->select_array('modelpdf',$modelpdf->liste_array(),$propal->modelpdf); + print ''; + print '
\n"; + + if ($propal->brouillon == 1) + { + print '
'; + } + + + /* + * Commandes rattachées + */ + if($conf->commande->enabled) + { + $coms = $propal->associated_orders(); + if (sizeof($coms) > 0) { - print '
'; - print_titre($langs->trans('SendPropalByMail')); - - $liste[0]=" "; - foreach ($societe->contact_email_array() as $key=>$value) { - $liste[$key]=$value; - } - - // Créé l'objet formulaire mail - include_once('../html.formmail.class.php'); - $formmail = new FormMail($db); - $formmail->fromname = $user->fullname; - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=$liste; - $formmail->withcc=1; - $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__'); - $formmail->withfile=1; - $formmail->withbody=1; - // Tableau des substitutions - $formmail->substit['__PROPREF__']=$propal->ref; - // Tableau des paramètres complémentaires - $formmail->param['action']='send'; - $formmail->param['models']='propal_send'; - $formmail->param['propalid']=$propal->id; - $formmail->param['returnurl']=DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; - - $formmail->show_form(); + print '
'; + print_titre($langs->trans('RelatedOrders')); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var=true; + for ($i = 0 ; $i < sizeof($coms) ; $i++) + { + $var=!$var; + print '\n"; + print ''; + print ''; + print "\n"; + } + print '
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'; + print ''.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."'.dolibarr_print_date($coms[$i]->date).''.$coms[$i]->total_ttc.'
'; } + } + + print '
'; + + /* + * Liste des actions propres à la propal + */ + $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ; + $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; + $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ; + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + if ($num) + { + print_titre($langs->trans('ActionsOnPropal')); + $i = 0; + $total = 0; + $var=true; + + print ''; + print ''; + print "\n"; + + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print ''; + print ''; + print '\n"; + print ''; + $authoract = new User($db); + $authoract->id = $objp->fk_user_author; + $authoract->fetch(''); + print ''; + print "\n"; + $i++; + } + print '
'.$langs->trans('Ref').''.$langs->trans('Date').''.$langs->trans('Action').''.$langs->trans('By').'
'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$authoract->code.'
'; + } + } + else + { + dolibarr_print_error($db); + } + + print '
'; + + + + /* + * Action presend + * + */ + if ($_GET['action'] == 'presend') + { + print '
'; + print_titre($langs->trans('SendPropalByMail')); + + $liste[0]=" "; + foreach ($societe->contact_email_array() as $key=>$value) { + $liste[$key]=$value; + } + + // Créé l'objet formulaire mail + include_once('../html.formmail.class.php'); + $formmail = new FormMail($db); + $formmail->fromname = $user->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=$liste; + $formmail->withcc=1; + $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__'); + $formmail->withfile=1; + $formmail->withbody=1; + // Tableau des substitutions + $formmail->substit['__PROPREF__']=$propal->ref; + // Tableau des paramètres complémentaires + $formmail->param['action']='send'; + $formmail->param['models']='propal_send'; + $formmail->param['propalid']=$propal->id; + $formmail->param['returnurl']=DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; + + $formmail->show_form(); + } } else { - /**************************************************************************** - * * - * Mode Liste des propales * - * * - ****************************************************************************/ + /**************************************************************************** + * * + * Mode Liste des propales * + * * + ****************************************************************************/ - $sortorder=$_GET['sortorder']; - $sortfield=$_GET['sortfield']; - $page=$_GET['page']; - $viewstatut=$_GET['viewstatut']; + $sortorder=$_GET['sortorder']; + $sortfield=$_GET['sortfield']; + $page=$_GET['page']; + $viewstatut=$_GET['viewstatut']; - if (! $sortfield) $sortfield='p.datep'; - if (! $sortorder) $sortorder='DESC'; - $limit = $conf->liste_limit; - $offset = $limit * $page ; - $pageprev = $page - 1; - $pagenext = $page + 1; + if (! $sortfield) $sortfield='p.datep'; + if (! $sortorder) $sortorder='DESC'; + $limit = $conf->liste_limit; + $offset = $limit * $page ; + $pageprev = $page - 1; + $pagenext = $page + 1; - $sql = 'SELECT s.nom, s.idp, s.client, p.rowid as propalid, p.price, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp,'.$db->pdate('p.fin_validite').' as dfv'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p'; - $sql.= ' WHERE p.fk_soc = s.idp'; + $sql = 'SELECT s.nom, s.idp, s.client, p.rowid as propalid, p.price, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp,'.$db->pdate('p.fin_validite').' as dfv'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p'; + $sql.= ' WHERE p.fk_soc = s.idp'; - if (!empty($_GET['search_ref'])) + if (!empty($_GET['search_ref'])) + { + $sql .= " AND p.ref LIKE '%".$_GET['search_ref']."%'"; + } + if (!empty($_GET['search_societe'])) + { + $sql .= " AND s.nom LIKE '%".$_GET['search_societe']."%'"; + } + if (!empty($_GET['search_montant_ht'])) + { + $sql .= " AND p.price='".$_GET['search_montant_ht']."'"; + } + if ($_GET['socidp']) + { + $sql .= ' AND s.idp = '.$_GET['socidp']; + } + if ($_GET['viewstatut'] <> '') + { + $sql .= ' AND p.fk_statut in ('.$_GET['viewstatut'].')'; + } + if ($month > 0) + { + $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; + } + if ($year > 0) + { + $sql .= " AND date_format(p.datep, '%Y') = $year"; + } + if (strlen($_POST['sf_ref']) > 0) + { + $sql .= " AND p.ref like '%".$_POST["sf_ref"] . "%'"; + } + $sql .= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC'; + $sql .= $db->plimit($limit + 1,$offset); + $result=$db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&socidp='.$socidp,$sortfield,$sortorder,'',$num); + $i = 0; + print ''; + print ''; + print_liste_field_titre($langs->trans('Ref'),'propal.php','p.ref','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'',$sortfield); + print_liste_field_titre($langs->trans('Company'),'propal.php','s.nom','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'',$sortfield); + print_liste_field_titre($langs->trans('Date'),'propal.php','p.datep','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="center"',$sortfield); + print_liste_field_titre($langs->trans('DateEndPropalShort'),'propal.php','dfv','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="center"',$sortfield); + print_liste_field_titre($langs->trans('Price'),'propal.php','p.price','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="right"',$sortfield); + print_liste_field_titre($langs->trans('Status'),'propal.php','p.fk_statut','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'align="center"',$sortfield); + print "\n"; + // Lignes des champs de filtre + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + print ''; + + $var=true; + + while ($i < min($num,$limit)) { - $sql .= " AND p.ref LIKE '%".$_GET['search_ref']."%'"; - } - if (!empty($_GET['search_societe'])) - { - $sql .= " AND s.nom LIKE '%".$_GET['search_societe']."%'"; - } - if (!empty($_GET['search_montant_ht'])) - { - $sql .= " AND p.price='".$_GET['search_montant_ht']."'"; - } - if ($_GET['socidp']) - { - $sql .= ' AND s.idp = '.$_GET['socidp']; - } - if ($_GET['viewstatut'] <> '') - { - $sql .= ' AND p.fk_statut in ('.$_GET['viewstatut'].')'; - } - if ($month > 0) - { - $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; - } - if ($year > 0) - { - $sql .= " AND date_format(p.datep, '%Y') = $year"; - } - if (strlen($_POST['sf_ref']) > 0) - { - $sql .= " AND p.ref like '%".$_POST["sf_ref"] . "%'"; - } - $sql .= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC'; - $sql .= $db->plimit($limit + 1,$offset); - $result=$db->query($sql); + $objp = $db->fetch_object($result); + $now = time(); + $var=!$var; + print ''; + print '\n"; - if ($result) - { - $num = $db->num_rows($result); - print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&socidp='.$socidp,$sortfield,$sortorder,'',$num); - $i = 0; - print '
'; + print ''; + print ''; + print ''; + print ' '; + print ''; + print ''; + print '
'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."
'; - print ''; - print_liste_field_titre($langs->trans('Ref'),'propal.php','p.ref','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'',$sortfield); - print_liste_field_titre($langs->trans('Company'),'propal.php','s.nom','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'',$sortfield); - print_liste_field_titre($langs->trans('Date'),'propal.php','p.datep','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="center"',$sortfield); - print_liste_field_titre($langs->trans('DateEndPropalShort'),'propal.php','dfv','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="center"',$sortfield); - print_liste_field_titre($langs->trans('Price'),'propal.php','p.price','','&socidp='.$socidp.'&viewstatut='.$viewstatut, 'align="right"',$sortfield); - print_liste_field_titre($langs->trans('Status'),'propal.php','p.fk_statut','','&socidp='.$socidp.'&viewstatut='.$viewstatut,'align="center"',$sortfield); - print "\n"; - // Lignes des champs de filtre - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - print ''; + if ($objp->client == 1) + { + $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp; + } + else + { + $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp; + } + print ''; - $var=true; + // Date propale + print ''; - print '\n"; + print strftime('%d',$objp->dp)."\n"; + print ' '; + print dolibarr_print_date($objp->dp,'%b')."\n"; + print ' '; + print strftime('%Y',$objp->dp)."\n"; - if ($objp->client == 1) - { - $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp; - } - else - { - $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp; - } - print ''; + // Date fin validite + if ( $now > $objp->dfv && $objp->dfv > 0 ) + { + print ''; + } + else + { + print ''; + } - // Date propale - print '\n"; + $propal=New Propal($db); + print '\n"; + print "\n"; - print strftime('%d',$objp->dp)."\n"; - print ' '; - print dolibarr_print_date($objp->dp,'%b')."\n"; - print ' '; - print strftime('%Y',$objp->dp)."\n"; + $total = $total + $objp->price; + $subtotal = $subtotal + $objp->price; - // Date fin validite - if ( $now > $objp->dfv && $objp->dfv > 0 ) - { - print ''; - } - else - { - print ''; - } - - print '\n"; - $propal=New Propal($db); - print '\n"; - print "\n"; - - $total = $total + $objp->price; - $subtotal = $subtotal + $objp->price; - - $i++; - } - print '
'; - print ''; - print ''; - print ''; - print ' '; - print ''; - print ''; - print '
'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.''; + $y = strftime('%Y',$objp->dp); + $m = strftime('%m',$objp->dp); - while ($i < min($num,$limit)) - { - $objp = $db->fetch_object($result); - $now = time(); - $var=!$var; - print '
'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.''.dolibarr_print_date($objp->dfv).' '; - $y = strftime('%Y',$objp->dp); - $m = strftime('%m',$objp->dp); + print ''.price($objp->price)."'.$propal->LibStatut($objp->fk_statut,0)."
'.dolibarr_print_date($objp->dfv).' '.price($objp->price)."'.$propal->LibStatut($objp->fk_statut,0)."
'; - $db->free($result); - } - else - { - dolibarr_print_error($db); + $i++; } + print ''; + $db->free($result); + } + else + { + dolibarr_print_error($db); + } } $db->close(); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 91fead53690..e903b987c6d 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -159,21 +159,65 @@ class Propal } } } - + /** + * \brief Mise à jour d'une ligne de produit + * \param id id de la ligne + * \param subprice prix unitaire + * \param qty quantité + * \param remise_percent remise effectuée sur le produit + * \return int 0 en cas de succès + */ + + function UpdateLigne($id, $subprice, $qty, $remise_percent=0) + { + if ($this->statut == 0) + { + $price = $subprice; + if ($remise_percent > 0) + { + $remise = round(($subprice * $remise_percent / 100), 2); + $price = $subprice - $remise; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet "; + $sql .= " SET qty='".$qty."'"; + $sql .= " , price='". ereg_replace(",",".",$price)."'"; + $sql .= " , remise_percent='".ereg_replace(",",".",$remise_percent)."'"; + $sql .= " , subprice='".ereg_replace(",",".",$subprice)."'"; + $sql .= " WHERE rowid = '".$id."';"; + + if ($this->db->query($sql) ) + { + $this->update_price(); + + return 0; + } + else + { + dolibarr_syslog("Propal::UpdateLigne Erreur -1"); + return -1; + } + } + else + { + dolibarr_syslog("Propal::UpdateLigne Erreur -2 Propal en mode incompatible pour cette action"); + return -2; + } + } /** * * */ - + function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $remise_percent=0) - { - if ($this->statut == 0) - { - if (strlen(trim($p_qty)) == 0) - { - $p_qty = 1; - } - + { + if ($this->statut == 0) + { + if (strlen(trim($p_qty)) == 0) + { + $p_qty = 1; + } + $p_price = ereg_replace(",",".",$p_price); $price = $p_price; @@ -303,13 +347,13 @@ class Propal } } else - { - dolibarr_print_error($this->db); + { + //dolibarr_print_error($this->db); } } else { - dolibarr_print_error($this->db); + //dolibarr_print_error($this->db); } return $this->id; } @@ -374,144 +418,150 @@ class Propal * \brief Recupère de la base les caractéristiques d'une propale * \param rowid id de la propal à récupérer */ - function fetch($rowid) - { - $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate("datep")."as dp,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note, fk_projet, fk_statut, remise_percent, fk_user_author"; - $sql .= ", c.label as statut_label"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal"; - $sql .= "," . MAIN_DB_PREFIX."c_propalst as c"; - $sql .= " WHERE rowid=$rowid AND fk_statut = c.id"; + function fetch($rowid) + { + $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact"; + $sql .= " ,".$this->db->pdate("datep")."as dp"; + $sql .= " ,".$this->db->pdate("fin_validite")."as dfv, model_pdf, note"; + $sql .= " , fk_projet, fk_statut, remise_percent, fk_user_author"; + $sql .= ", c.label as statut_label"; + $sql .= " FROM ".MAIN_DB_PREFIX."propal"; + $sql .= "," . MAIN_DB_PREFIX."c_propalst as c"; + $sql .= " WHERE fk_statut = c.id"; + $sql .= " AND rowid='".$rowid."';"; + + $resql=$this->db->query($sql); + + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $rowid; + + $this->datep = $obj->dp; + $this->fin_validite = $obj->dfv; + $this->date = $obj->dp; + $this->ref = $obj->ref; + $this->price = $obj->price; + $this->remise = $obj->remise; + $this->remise_percent = $obj->remise_percent; + $this->total = $obj->total; + $this->total_ht = $obj->price; + $this->total_tva = $obj->tva; + $this->total_ttc = $obj->total; + $this->socidp = $obj->fk_soc; + $this->soc_id = $obj->fk_soc; + $this->projetidp = $obj->fk_projet; + $this->contactid = $obj->fk_soc_contact; + $this->modelpdf = $obj->model_pdf; + $this->note = $obj->note; + $this->statut = $obj->fk_statut; + $this->statut_libelle = $obj->statut_label; + + $this->user_author_id = $obj->fk_user_author; + + if ($obj->fk_statut == 0) + { + $this->brouillon = 1; + } - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); + $this->lignes = array(); + $this->db->free($resql); + + $this->ref_url = ''.$this->ref.''; - $this->id = $rowid; - - $this->datep = $obj->dp; - $this->fin_validite = $obj->dfv; - $this->date = $obj->dp; - $this->ref = $obj->ref; - $this->price = $obj->price; - $this->remise = $obj->remise; - $this->remise_percent = $obj->remise_percent; - $this->total = $obj->total; - $this->total_ht = $obj->price; - $this->total_tva = $obj->tva; - $this->total_ttc = $obj->total; - $this->socidp = $obj->fk_soc; - $this->soc_id = $obj->fk_soc; - $this->projetidp = $obj->fk_projet; - $this->contactid = $obj->fk_soc_contact; - $this->modelpdf = $obj->model_pdf; - $this->note = $obj->note; - $this->statut = $obj->fk_statut; - $this->statut_libelle = $obj->statut_label; + /* + * Lignes produits + */ + + $sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."product as p"; + $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC"; + + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; - $this->user_author_id = $obj->fk_user_author; + while ($i < $num) + { + $objp = $this->db->fetch_object($result); - if ($obj->fk_statut == 0) - { - $this->brouillon = 1; - } + $ligne = new PropaleLigne(); + $ligne->libelle = stripslashes($objp->label); + $ligne->desc = stripslashes($objp->description); + $ligne->qty = $objp->qty; + $ligne->ref = $objp->ref; + $ligne->tva_tx = $objp->tva_tx; + $ligne->subprice = $objp->subprice; + $ligne->remise_percent = $objp->remise_percent; + $ligne->price = $objp->price; + $ligne->product_id = $objp->rowid; - $this->lignes = array(); - $this->db->free(); + $this->lignes[$i] = $ligne; + $i++; + } + $this->db->free($result); + } + else + { + dolibarr_syslog("Propal::Fetch Erreur lecture des produits"); + return -1; + } - $this->ref_url = ''.$this->ref.''; + /* + * Lignes propales + */ + $sql = "SELECT d.qty, d.description, d.price, d.subprice, d.tva_tx, d.rowid, d.remise_percent"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d"; + $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = 0"; - /* - * Lignes produits - */ + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $j = 0; - $sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC"; + while ($j < $num) + { + $objp = $this->db->fetch_object($result); + $ligne = new PropaleLigne(); + $ligne->libelle = stripslashes($objp->description); + $ligne->desc = stripslashes($objp->description); + $ligne->qty = $objp->qty; + $ligne->ref = $objp->ref; + $ligne->tva_tx = $objp->tva_tx; + $ligne->subprice = $objp->subprice; + $ligne->remise_percent = $objp->remise_percent; + $ligne->price = $objp->price; + $ligne->product_id = 0; - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; + $this->lignes[$i] = $ligne; + $i++; + $j++; + } - while ($i < $num) - { - $objp = $this->db->fetch_object($result); - - $ligne = new PropaleLigne(); - $ligne->libelle = stripslashes($objp->label); - $ligne->desc = stripslashes($objp->description); - $ligne->qty = $objp->qty; - $ligne->ref = $objp->ref; - $ligne->tva_tx = $objp->tva_tx; - $ligne->subprice = $objp->subprice; - $ligne->remise_percent = $objp->remise_percent; - $ligne->price = $objp->price; - $ligne->product_id = $objp->rowid; - - $this->lignes[$i] = $ligne; - $i++; - } - $this->db->free($result); - } - else - { - dolibarr_print_error($this->db); - return -1; - } - - /* - * Lignes propales - */ - $sql = "SELECT d.qty, d.description, d.price, d.subprice, d.tva_tx, d.rowid, d.remise_percent"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d"; - $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = 0"; - - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $j = 0; - - while ($j < $num) - { - $objp = $this->db->fetch_object($result); - $ligne = new PropaleLigne(); - $ligne->libelle = stripslashes($objp->description); - $ligne->desc = stripslashes($objp->description); - $ligne->qty = $objp->qty; - $ligne->ref = $objp->ref; - $ligne->tva_tx = $objp->tva_tx; - $ligne->subprice = $objp->subprice; - $ligne->remise_percent = $objp->remise_percent; - $ligne->price = $objp->price; - $ligne->product_id = 0; - - $this->lignes[$i] = $ligne; - $i++; - $j++; - } - - $this->db->free($result); - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - + $this->db->free($result); + } + else + { + dolibarr_syslog("Propal::Fetch Erreur lecture des lignes de propale"); + + return -1; + } + } + return 1; + } + else + { + dolibarr_syslog("Propal::Fetch Erreur lecture de la propale $rowid"); + return -1; + } + } + /* * * @@ -532,7 +582,7 @@ class Propal } else { - dolibarr_print_error($this->db); + //dolibarr_print_error($this->db); return -1; } } @@ -545,89 +595,90 @@ class Propal */ function set_remise($user, $remise) - { - if ($user->rights->propale->creer) - { - $remise = ereg_replace(",",".",$remise); - - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; - $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; - - if ($this->db->query($sql) ) - { - $this->remise_percent = $remise; - $this->update_price(); - return 1; - } - else - { - dolibarr_print_error($this->db); - } - } - } - + { + if ($user->rights->propale->creer) + { + $remise = ereg_replace(",",".",$remise); + + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; + $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; + + if ($this->db->query($sql) ) + { + $this->remise_percent = $remise; + $this->update_price(); + return 1; + } + else + { + dolibarr_syslog("Propal::set_remise Erreur SQL"); + } + } + } + /* * * * */ - function set_project($user, $project_id) - { - if ($user->rights->propale->creer) - { - //verif que le projet et la société concordent - $sql = 'SELECT p.rowid, p.title FROM '.MAIN_DB_PREFIX.'projet as p WHERE p.fk_soc ='.$this->socidp.' AND p.rowid='.$project_id; - $sqlres = $this->db->query($sql); - if ($sqlres) - { - $numprojet = $this->db->num_rows($sqlres); - if ($numprojet > 0) - { - $this->projetidp=$project_id; - $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_projet = '.$project_id; - $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; - $this->db->query($sql); - } - } - else - { - dolibarr_print_error($this->db); - } - } - } + function set_project($user, $project_id) + { + if ($user->rights->propale->creer) + { + //verif que le projet et la société concordent + $sql = 'SELECT p.rowid, p.title FROM '.MAIN_DB_PREFIX.'projet as p WHERE p.fk_soc ='.$this->socidp.' AND p.rowid='.$project_id; + $sqlres = $this->db->query($sql); + if ($sqlres) + { + $numprojet = $this->db->num_rows($sqlres); + if ($numprojet > 0) + { + $this->projetidp=$project_id; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_projet = '.$project_id; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + $this->db->query($sql); + } + } + else + { + + dolibarr_syslog("Propal::set_project Erreur SQL"); + } + } + } /* * * * */ - - function set_contact($user, $contact_id) - { - if ($user->rights->propale->creer) - { - //verif que le contact et la société concordent - $sql = 'SELECT p.idp FROM '.MAIN_DB_PREFIX.'socpeople as p WHERE p.fk_soc = '.$this->socidp.' AND p.idp='.$contact_id; - $sqlres = $this->db->query($sql); - if ($sqlres) - { - $numprojet = $this->db->num_rows($sqlres); - if ($numprojet > 0) - { - $this->projetidp=$project_id; - $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_soc_contact = '.$contact_id; - $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; - $this->db->query($sql); - } - } - else - { - dolibarr_print_error($this->db); - } - } - } - + + function set_contact($user, $contact_id) + { + if ($user->rights->propale->creer) + { + //verif que le contact et la société concordent + $sql = 'SELECT p.idp FROM '.MAIN_DB_PREFIX.'socpeople as p WHERE p.fk_soc = '.$this->socidp.' AND p.idp='.$contact_id; + $sqlres = $this->db->query($sql); + if ($sqlres) + { + $numprojet = $this->db->num_rows($sqlres); + if ($numprojet > 0) + { + $this->projetidp=$project_id; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_soc_contact = '.$contact_id; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;'; + $this->db->query($sql); + } + } + else + { + dolibarr_syslog("Propal::set_contact Erreur SQL"); + } + } + } + /* * * @@ -923,103 +974,103 @@ class Propal */ function update_note($note) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET note = '$note'"; - $sql .= " WHERE rowid = $this->id;"; - - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - - /** - * \brief Information sur l'objet propal - * \param id id de la propale - */ - function info($id) - { - $sql = "SELECT c.rowid, "; - $sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo"; - $sql.= ", fk_user_author, fk_user_valid, fk_user_cloture"; - $sql.= " FROM ".MAIN_DB_PREFIX."propal as c"; - $sql.= " WHERE c.rowid = $id"; + { + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET note = '$note'"; + $sql .= " WHERE rowid = $this->id;"; - if ($this->db->query($sql)) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + + /** + * \brief Information sur l'objet propal + * \param id id de la propale + */ + function info($id) + { + $sql = "SELECT c.rowid, "; + $sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo"; + $sql.= ", fk_user_author, fk_user_valid, fk_user_cloture"; + $sql.= " FROM ".MAIN_DB_PREFIX."propal as c"; + $sql.= " WHERE c.rowid = $id"; - $this->id = $obj->rowid; - - $this->date_creation = $obj->datec; - $this->date_validation = $obj->datev; - $this->date_cloture = $obj->dateo; - - $cuser = new User($this->db, $obj->fk_user_author); - $cuser->fetch(); - $this->user_creation = $cuser; - - if ($obj->fk_user_valid) - { - $vuser = new User($this->db, $obj->fk_user_valid); - $vuser->fetch(); - $this->user_validation = $vuser; - } - - if ($obj->fk_user_cloture) - { - $cluser = new User($this->db, $obj->fk_user_cloture); - $cluser->fetch(); - $this->user_cloture = $cluser; - } - - - } - $this->db->free(); - - } - else - { - dolibarr_print_error($this->db); - } - } - - + if ($this->db->query($sql)) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object(); + + $this->id = $obj->rowid; + + $this->date_creation = $obj->datec; + $this->date_validation = $obj->datev; + $this->date_cloture = $obj->dateo; + + $cuser = new User($this->db, $obj->fk_user_author); + $cuser->fetch(); + $this->user_creation = $cuser; + + if ($obj->fk_user_valid) + { + $vuser = new User($this->db, $obj->fk_user_valid); + $vuser->fetch(); + $this->user_validation = $vuser; + } + + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db, $obj->fk_user_cloture); + $cluser->fetch(); + $this->user_cloture = $cluser; + } + + + } + $this->db->free(); + + } + else + { + dolibarr_print_error($this->db); + } + } + + /** * \brief Retourne le libellé du statut d'une propale (brouillon, validée, ...) * \return string Libellé */ - function getLibStatut() - { - return $this->LibStatut($this->statut); - } - + function getLibStatut() + { + return $this->LibStatut($this->statut); + } + /** * \brief Renvoi le libellé d'un statut donné * \param statut id statut * \param size Libellé court si 0, long si non défini * \return string Libellé */ - function LibStatut($statut,$size=1) - { - if ($size) return $this->labelstatut[$statut]; - else return $this->labelstatut_short[$statut]; - } - + function LibStatut($statut,$size=1) + { + if ($size) return $this->labelstatut[$statut]; + else return $this->labelstatut_short[$statut]; + } + } class PropaleLigne { function PropaleLigne() - { - } + { + } } ?>