diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 9cea1cb99fd..a5110363b71 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -32,7 +32,7 @@ require("./pre.inc.php"); $user->getrights('facture'); $user->getrights('propale'); if (!$user->rights->propale->lire) - accessforbidden(); + accessforbidden(); if ($conf->projet->enabled) require_once '../project.class.php'; if ($conf->commande->enabled) require_once '../commande/commande.class.php'; @@ -43,48 +43,50 @@ require_once("../propal.class.php"); // Sécurité accés client if ($user->societe_id > 0) { - $action = ''; - $socidp = $user->societe_id; + $action = ''; + $socidp = $user->societe_id; } if ($_GET["action"] == 'setstatut') { - /* - * Classée la facture comme facturée - */ - $propal = new Propal($db); - $propal->id = $_GET["propalid"]; - $propal->cloture($user, $_GET["statut"], $note); + /* + * Classée la facture comme facturée + */ + $propal = new Propal($db); + $propal->id = $_GET["propalid"]; + $propal->cloture($user, $_GET["statut"], $note); } if ( $action == 'delete' ) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;"; - if ( $db->query($sql) ) + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;"; + if ( $db->query($sql) ) { - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;"; - if ( $db->query($sql) ) + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;"; + if ( $db->query($sql) ) { - print '
'.$langs->trans("Deleted").'
'; + print '
'.$langs->trans("Deleted").'
'; } - else + else { - dolibarr_print_error($db); + dolibarr_print_error($db); } } - else + else { - dolibarr_print_error($db); + dolibarr_print_error($db); } - $propalid = 0; - $brouillon = 1; + $propalid = 0; + $brouillon = 1; } llxHeader(); +$form = new Form($db); + /* * * Mode fiche @@ -92,619 +94,588 @@ llxHeader(); */ if ($_GET["propalid"]) { - $propal = new Propal($db); - $propal->fetch($_GET["propalid"]); - $h=0; - - $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('CommercialCard'); - $h++; - - $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('AccountancyCard'); - $hselected=$h; - $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/document.php?propalid='.$propal->id; - $head[$h][1] = $langs->trans('Documents'); - $h++; - - dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref); - - - /* - * Fiche propal - * - */ - $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref,'.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst, 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.'c_propalst as c, '.MAIN_DB_PREFIX.'socpeople as x'; - $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = '.$propal->id; - if ($socidp) $sql .= ' AND s.idp = '.$socidp; - - $result = $db->query($sql); - if ($result) + $propal = new Propal($db); + $propal->fetch($_GET["propalid"]); + $h=0; + + $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('CommercialCard'); + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('AccountancyCard'); + $hselected=$h; + $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/document.php?propalid='.$propal->id; + $head[$h][1] = $langs->trans('Documents'); + $h++; + + dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref); + + + /* + * Fiche propal + * + */ + $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref,'.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst, 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.'c_propalst as c, '.MAIN_DB_PREFIX.'socpeople as x'; + $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = '.$propal->id; + if ($socidp) $sql .= ' AND s.idp = '.$socidp; + + $resql = $db->query($sql); + if ($resql) + { + if ($db->num_rows($resql)) { - if ($db->num_rows($result)) + $obj = $db->fetch_object($resql); + + $societe = new Societe($db); + $societe->fetch($obj->idp); + + print ''; + $rowspan=6; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + + // Receiver + $langs->load('mails'); + print ''; + print ''; + + if ($conf->projet->enabled) + $rowspan++; + + print ''; + + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''; + $numprojet = $societe->has_projects(); + 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 ''; + 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').''; + + $dests=$societe->contact_array($societe->id); + $numdest = count($dests); + if ($numdest==0) + { + print 'Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale
'; + print ''.$langs->trans('AddContact').''; + } + else + { + if ($propal->statut == 0 && $user->rights->propale->creer) { - $obj = $db->fetch_object($result); - - $societe = new Societe($db); - $societe->fetch($obj->idp); - - print ''; - $rowspan=6; - print ''; - print ''; - print ''; - print ''; - - print ''; - - print ''; - print ''; - - // Receiver - $langs->load('mails'); - print ''; - print ''; - print ''; - - if ($conf->projet->enabled) - $rowspan++; - - print ''; - - if ($conf->projet->enabled) - { - $langs->load("projects"); - print ''; - $numprojet = $societe->has_projects(); - 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').''; - - $dests=$societe->contact_array($societe->id); - $numdest = count($dests); - if ($numdest==0) - { - print 'Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale
'; - print ''.$langs->trans('AddContact').''; - } - else - { - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print '
'; - print ''; - $form->select_contacts($societe->id, $propal->contactid, 'contactidp'); - print ''; - print '
'; - } - else - { - if (!empty($propal->contactid)) - { - 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').''; - if (! $numprojet) - { - 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 '
'; - $proj = new Project($db); - $proj->fetch($propal->projetidp); - print ''; - print $proj->title; - print ''; - print ' 
'.$langs->trans('GlobalDiscount').'
% '; - 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 facture - // \todo - - - $total = $total + ($objp->qty * $objp->price); - $i++; - } - $db->free($result); - } - else - { - dolibarr_print_error($db); - } - - 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 '  
'; - + print '
'; + print ''; + $form->select_contacts($societe->id, $propal->contactid, 'contactidp'); + print ''; + print '
'; } - } - else - { - dolibarr_print_error($db); - } + else + { + if (!empty($propal->contactid)) + { + 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').''; + if (! $numprojet) + { + 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 '
'; + $proj = new Project($db); + $proj->fetch($propal->projetidp); + print ''; + print $proj->title; + print ''; + print ' 
'.$langs->trans('GlobalDiscount').'
% '; + 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'; + $resql = $db->query($sql); + if ($resql) + { + $num_lignes = $db->num_rows($resql); + $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($resql); + $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"; + + print ''; + + print ''; + } + // Update ligne de facture + // \todo + + + $total = $total + ($objp->qty * $objp->price); + $i++; + } + $db->free($resql); + } + else + { + dolibarr_print_error($db); + } + + 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)."  
'; + + } + } + else + { + dolibarr_print_error($db); + } + + print ''; - /* - * Boutons Actions - */ - if ($obj->statut <> 4 && $user->societe_id == 0) + /* + * Boutons Actions + */ + if ($obj->statut <> 4 && $user->societe_id == 0) { - print '
'; + print '
'; - if ($obj->statut == 2 && $user->rights->facture->creer) + if ($obj->statut == 2 && $user->rights->facture->creer) { - print '".$langs->trans("BuildBill").""; + print '".$langs->trans("BuildBill").""; } - if ($obj->statut == 2 && sizeof($propal->facture_liste_array())) + if ($obj->statut == 2 && sizeof($propal->facture_liste_array())) { - print '".$langs->trans("ClassifyBilled").""; + print '".$langs->trans("ClassifyBilled").""; } - print "
"; + print "
"; } - print ''; + print ''; + print '\n"; + print ''; + $authoract = new User($db); + $authoract->id = $objp->fk_user_author; + $authoract->fetch(''); + print ''; + print "\n"; + $i++; + } + print '
'; + print '\n"; + print "
'; - /* - * Documents - */ - if ($propal->brouillon == 1) - { - print '
'; - print ''; - } - print_titre($langs->trans('Documents')); + /* + * Documents + */ - print ''; - $propref = sanitize_string($propal->ref); - $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; - $relativepath = $propref.'/'.$propref.'.pdf'; + print_titre($langs->trans('Documents')); - $var=true; + print '
'; + $propref = sanitize_string($propal->ref); + $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; + $relativepath = $propref.'/'.$propref.'.pdf'; - if (file_exists($file)) - { - print ''; - print ''; - print ''; - print ''; - } + $var=true; - 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('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.'
'; - } - } - - - /* - * Factures associees - */ - $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id; - - $result = $db->query($sql); - if ($result) + if (file_exists($file)) { - $num_fac_asso = $db->num_rows($result); - $i = 0; $total = 0; - print "
"; - if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills")); - else print_titre($langs->trans("RelatedBill")); - print ''; - print ""; - print ''; - print ''; - print ''; - print "\n"; + print ''; + print ''; + print ''; + print ''; + } - $var=True; - while ($i < $num_fac_asso) + print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'.$langs->trans('Propal').' PDF'.$propal->ref.'.pdf'.filesize($file). ' bytes'.strftime('%d %B %Y %H:%M:%S',filemtime($file)).'
\n"; + + + /* + * Commandes rattachées + */ + if($conf->commande->enabled) + { + $coms = $propal->associated_orders(); + if (sizeof($coms) > 0) + { + 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.'
'; + } + } + + + /* + * Factures associees + */ + $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.paye"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id; + + $resql = $db->query($sql); + if ($resql) + { + $num_fac_asso = $db->num_rows($resql); + $i = 0; $total = 0; + print "
"; + if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills")); + else print_titre($langs->trans("RelatedBill")); + print ''; + print ""; + print ''; + print ''; + print ''; + print "\n"; + + $var=True; + while ($i < $num_fac_asso) { - $objp = $db->fetch_object(); - $var=!$var; - print ""; - print '"; + print '\n"; - print ''; - print ''; - print ""; - $total = $total + $objp->total; - $i++; + print "\n"; + print ''; + print ''; + print ""; + $total = $total + $objp->total; + $i++; } - print "\n"; - print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.''; - if ($objp->paye) + $objp = $db->fetch_object(); + $var=!$var; + print "
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.''; + if ($objp->paye) { - print " (payée)"; + print " (payée)"; } - print "'.dolibarr_print_date($objp->df).''.price($objp->total).'
'.dolibarr_print_date($objp->df).''.price($objp->total).'
".$langs->trans("TotalHT")."".price($total)."
"; - $db->free(); + print "
".$langs->trans("TotalHT")."".price($total)."
"; + $db->free(); } - print '
'; + 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) + /* + * 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 ; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + if ($num) { - $num = $db->num_rows($result); - if ($num) - { - print_titre($langs->trans('ActionsOnPropal')); - $i = 0; - $total = 0; - $var=true; + print_titre($langs->trans('ActionsOnPropal')); + $i = 0; + $total = 0; + $var=true; - print ''; - print ''; - print "\n"; + print '
'.$langs->trans('Ref').''.$langs->trans('Date').''.$langs->trans('Action').''.$langs->trans('By').'
'; + 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); + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + print '
'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$authoract->code.'
'; } + } + else + { + dolibarr_print_error($db); + } - print ''; + print ''; } else { - /** - * - * Mode Liste des propales - * - */ + /** + * + * Mode Liste des propales + * + */ - if (! $sortfield) $sortfield="p.datep"; - if (! $sortorder) $sortorder="DESC"; - if ($page == -1) $page = 0 ; + if (! $sortfield) $sortfield="p.datep"; + if (! $sortorder) $sortorder="DESC"; + if ($page == -1) $page = 0 ; - $pageprev = $page - 1; - $pagenext = $page + 1; - $limit = $conf->liste_limit; - $offset = $limit * $page ; + $pageprev = $page - 1; + $pagenext = $page + 1; + $limit = $conf->liste_limit; + $offset = $limit * $page ; - $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p "; - $sql.= " WHERE p.fk_soc = s.idp"; - if ($socidp) $sql .= " AND s.idp = $socidp"; - if ($viewstatut <> '') $sql .= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons séparé par virgules - if ($month > 0) $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; - if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = $year"; - $sql .= " ORDER BY $sortfield $sortorder, p.rowid DESC "; - $sql .= $db->plimit($limit + 1,$offset); + $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.fk_statut, ".$db->pdate("p.datep")." as dp"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p "; + $sql.= " WHERE p.fk_soc = s.idp"; + if ($socidp) $sql .= " AND s.idp = $socidp"; + if ($viewstatut <> '') $sql .= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons séparé par virgules + if ($month > 0) $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; + if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = $year"; + $sql .= " ORDER BY $sortfield $sortorder, p.rowid DESC "; + $sql .= $db->plimit($limit + 1,$offset); - if ( $db->query($sql) ) + if ( $db->query($sql) ) { - $num = $db->num_rows(); + $num = $db->num_rows(); - $propalstatic=new Propal($db); + $propalstatic=new Propal($db); - print_barre_liste($langs->trans("Proposals"), $page, "propal.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); + print_barre_liste($langs->trans("Proposals"), $page, "propal.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); - $i = 0; - print ""; - print ''; - print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&year=$year&viewstatut=$viewstatut",'',$sortfield); - print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield); - print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right" colspan="2"',$sortfield); - print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); - print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="center"',$sortfield); - print "\n"; + $i = 0; + print "
"; + print ''; + print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&year=$year&viewstatut=$viewstatut",'',$sortfield); + print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield); + print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right" colspan="2"',$sortfield); + print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); + print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="center"',$sortfield); + print "\n"; - while ($i < min($num, $limit)) + while ($i < min($num, $limit)) { - $objp = $db->fetch_object(); + $objp = $db->fetch_object(); - $var=!$var; - print ""; + $var=!$var; + print ""; - print '\n"; + print '\n"; - print "\n"; + print "\n"; - $now = time(); - $lim = 3600 * 24 * 15 ; + $now = time(); + $lim = 3600 * 24 * 15 ; - if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 ) + if ( ($now - $objp->dp) > $lim && $objp->statutid == 1 ) { - print ""; + print ""; } - else + else { - print ""; + print ""; } - print "\n"; + print strftime("%d",$objp->dp)."\n"; + print " "; + print strftime("%B",$objp->dp)."\n"; + print " "; + print strftime("%Y",$objp->dp)."\n"; - print "\n"; - print "\n"; - print "\n"; + print "\n"; + print "\n"; + print "\n"; - $i++; + $i++; } - print "
'.img_object($langs->trans("ShowPropal"),"propal")." \n"; - print ''.$objp->ref."'.img_object($langs->trans("ShowPropal"),"propal")." \n"; + print ''.$objp->ref."idp\">$objp->nomidp\">$objp->nom > 15 jours > 15 jours  "; - $y = strftime("%Y",$objp->dp); - $m = strftime("%m",$objp->dp); + print ""; + $y = strftime("%Y",$objp->dp); + $m = strftime("%m",$objp->dp); - print strftime("%d",$objp->dp)."\n"; - print " "; - print strftime("%B",$objp->dp)."\n"; - print " "; - print strftime("%Y",$objp->dp)."".price($objp->price)."".$propalstatic->LibStatut($objp->fk_statut,0)."
".price($objp->price)."".$propalstatic->LibStatut($objp->fk_statut,0)."
"; - $db->free(); + print ""; + $db->free(); } - else + else { - dolibarr_print_error($db); + dolibarr_print_error($db); } } $db->close();