* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2010-2011 Philippe Grand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/comm/propal.php * \ingroup propale * \brief Page of commercial proposals card and list * \version $Id: propal.php,v 1.614 2011/08/03 00:46:26 eldy Exp $ */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'); require_once(DOL_DOCUMENT_ROOT."/includes/modules/propale/modules_propale.php"); require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/propal.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'); $langs->load('companies'); $langs->load('propal'); $langs->load('compta'); $langs->load('bills'); $langs->load('orders'); $langs->load('products'); $id=GETPOST('id'); $ref=GETPOST('ref'); $socid=GETPOST('socid'); $action=GETPOST('action'); $confirm=GETPOST('confirm'); $lineid=GETPOST('lineid'); $sall=GETPOST("sall"); $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg")); $year=GETPOST("year"); $month=GETPOST("month"); // Nombre de ligne pour choix de produit/service predefinis $NBLINES=4; $object = new Propal($db); // Security check $module='propale'; if (isset($socid)) { $objectid=$socid; $module='societe'; $dbtable=''; } else if (isset($id) && $id > 0) { $objectid=$id; $module='propale'; $dbtable='propal'; } if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, $module, $objectid, $dbtable); // Instantiate hooks of thirdparty module if (is_array($conf->hooks_modules) && ! empty($conf->hooks_modules)) { $object->callHooks('propalcard'); } /******************************************************************************/ /* Actions */ /******************************************************************************/ // Hook of actions if (! empty($object->hooks)) { foreach($object->hooks as $hook) { if (! empty($hook['modules'])) { foreach($hook['modules'] as $module) { if (method_exists($module,'doActions')) { $reshook+=$module->doActions($object); if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0)) { $mesg=$module->error; $mesgs[]=$module->errors; if ($action=='add') $action='create'; if ($action=='update') $action='edit'; } } } } } } // Action clone object if ($action == 'confirm_clone' && $confirm == 'yes') { if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers') ) { $mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
'; } else { $result=$object->createFromClone($id,0,GETPOST('socid')); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit; } else { $mesg=$object->error; $action=''; //$_GET['id']=$_REQUEST['id']; } } } // Suppression de la propale if ($action == 'confirm_delete' && $confirm == 'yes') { if ($user->rights->propale->supprimer) { $object->fetch($id); $result=$object->delete($user); $id = 0; $brouillon = 1; if ($result > 0) { Header('Location: '.$_SERVER["PHP_SELF"]); exit; } else { $langs->load("errors"); if ($object->error == 'ErrorFailToDeleteDir') $mesg='
'.$langs->trans('ErrorFailedToDeleteJoinedFiles').'
'; else $mesg='
'.$object->error.'
'; } } } // Remove line if ($action == 'confirm_deleteline' && $confirm == 'yes') { if ($user->rights->propale->creer) { $object->fetch($id); $object->fetch_thirdparty(); $result = $object->deleteline($lineid); // reorder lines if ($result) $object->line_order(true); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); exit; } else { $mesg='
'.$object->error.'
'; } } // Validation if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propale->valider) { $object->fetch($id); $object->fetch_thirdparty(); $result=$object->valid($user); if ($result >= 0) { // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); } else { $mesg='
'.$object->error.'
'; } } if ($_POST['action'] == 'setdate') { $object->fetch($id); $result=$object->set_date($user,dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear'])); if ($result < 0) dol_print_error($db,$object->error); } if ($_POST['action'] == 'setecheance') { $object->fetch($id); $result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); if ($result < 0) dol_print_error($db,$object->error); } if ($_POST['action'] == 'setdate_livraison') { $object->fetch($id); $result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); if ($result < 0) dol_print_error($db,$object->error); } if ($_POST['action'] == 'setaddress' && $user->rights->propale->creer) { $object->fetch($id); $result=$object->set_adresse_livraison($user,$_POST['fk_address']); if ($result < 0) dol_print_error($db,$object->error); } // Positionne ref client if ($_POST['action'] == 'set_ref_client' && $user->rights->propale->creer) { $object->fetch($id); $object->set_ref_client($user, $_POST['ref_client']); } /* * Creation propale */ if ($_POST['action'] == 'add' && $user->rights->propale->creer) { $object->socid=$_POST['socid']; $object->fetch_thirdparty(); $db->begin(); // Si on a selectionne une propal a copier, on realise la copie if($_POST['createmode']=='copy' && $_POST['copie_propal']) { if ($object->fetch($_POST['copie_propal']) > 0) { $object->ref = $_POST['ref']; $object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); $object->availability_id = $_POST['availability_id']; $object->demand_reason_id = $_POST['demand_reason_id']; $object->fk_delivery_address = $_POST['fk_address']; $object->duree_validite = $_POST['duree_validite']; $object->cond_reglement_id = $_POST['cond_reglement_id']; $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->remise_percent = $_POST['remise_percent']; $object->remise_absolue = $_POST['remise_absolue']; $object->socid = $_POST['socid']; $object->contactid = $_POST['contactidp']; $object->fk_project = $_POST['projectid']; $object->modelpdf = $_POST['model']; $object->author = $user->id; // deprecated $object->note = $_POST['note']; $object->statut = 0; $id = $object->create_from($user); } else { $mesg = '
'.$langs->trans("ErrorFailedToCopyProposal",$_POST['copie_propal']).'
'; } } else { $object->ref = $_POST['ref']; $object->ref_client = $_POST['ref_client']; $object->datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $object->date_livraison = dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); $object->availability_id = $_POST['availability_id']; $object->demand_reason_id = $_POST['demand_reason_id']; $object->fk_delivery_address = $_POST['fk_address']; $object->duree_validite = $_POST['duree_validite']; $object->cond_reglement_id = $_POST['cond_reglement_id']; $object->mode_reglement_id = $_POST['mode_reglement_id']; $object->contactid = $_POST['contactidp']; $object->fk_project = $_POST['projectid']; $object->modelpdf = $_POST['model']; $object->author = $user->id; // deprecated $object->note = $_POST['note']; $object->origin = $_POST['origin']; $object->origin_id = $_POST['originid']; for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) { if ($_POST['idprod'.$i]) { $xid = 'idprod'.$i; $xqty = 'qty'.$i; $xremise = 'remise'.$i; $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); } } $id = $object->create($user); } if ($id > 0) { $error=0; // Insertion contact par defaut si defini if ($_POST["contactidp"]) { $result=$object->add_contact($_POST["contactidp"],'CUSTOMER','external'); if ($result > 0) { $error=0; } else { $mesg = '
'.$langs->trans("ErrorFailedToAddContact").'
'; $error=1; } } if (! $error) { $db->commit(); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); exit; } else { $db->rollback(); } } else { dol_print_error($db,$object->error); $db->rollback(); exit; } } // Classify billed if ($action == 'classifybilled') { $object->fetch($id); $object->cloture($user, 4, ''); } /* * Cloture de la propale */ if (GETPOST('action') == 'setstatut' && $user->rights->propale->cloturer) { if (! $_POST['cancel']) { if (! GETPOST('statut')) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("CloseAs")).'
'; $action='statut'; $action='statut'; } else { $object->fetch($id); // prevent browser refresh from closing proposal several times if ($object->statut==1) { $object->cloture($user, $_REQUEST['statut'], $_REQUEST['note']); } } } } /* * Add file in email form */ if ($_POST['addfile']) { require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); // Set tmp user directory TODO Use a dedicated directory for temp mails files $vardir=$conf->user->dir_output."/".$user->id; $upload_dir_tmp = $vardir.'/temp'; $mesg=dol_add_file_process($upload_dir_tmp,0,0); $action='presend'; $_POST["action"]='presend'; } /* * Remove file in email form */ if (! empty($_POST['removedfile'])) { require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); // Set tmp user directory $vardir=$conf->user->dir_output."/".$user->id; $upload_dir_tmp = $vardir.'/temp'; $mesg=dol_remove_file_process($_POST['removedfile'],0); $action='presend'; $_POST["action"]='presend'; } /* * Send mail */ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) { $langs->load('mails'); $result=$object->fetch($_POST["id"]); $result=$object->fetch_thirdparty(); if ($result > 0) { $objectref = dol_sanitizeFileName($object->ref); $file = $conf->propale->dir_output . '/' . $objectref . '/' . $objectref . '.pdf'; if (is_readable($file)) { if ($_POST['sendto']) { // Le destinataire a ete fourni via le champ libre $sendto = $_POST['sendto']; $sendtoid = 0; } elseif ($_POST['receiver'] != '-1') { // Recipient was provided from combo list if ($_POST['receiver'] == 'thirdparty') // Id of third party { $sendto = $object->client->email; $sendtoid = 0; } else // Id du contact { $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); $sendtoid = $_POST['receiver']; } } if (dol_strlen($sendto)) { $langs->load("commercial"); $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; $message = $_POST['message']; $sendtocc = $_POST['sendtocc']; $deliveryreceipt = $_POST['deliveryreceipt']; if ($_POST['action'] == 'send') { if (dol_strlen($_POST['subject'])) $subject = $_POST['subject']; else $subject = $langs->transnoentities('Propal').' '.$object->ref; $actiontypecode='AC_PROP'; $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; if ($message) { $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; $actionmsg.=$message; } $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); } // Create form object include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); $formmail = new FormMail($db); $attachedfiles=$formmail->get_attached_files(); $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; // Envoi de la propal require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php'); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); if ($mailfile->error) { $mesg='
'.$mailfile->error.'
'; } else { $result=$mailfile->sendfile(); if ($result) { $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain " $error=0; // Initialisation donnees $object->sendtoid = $sendtoid; $object->actiontypecode = $actiontypecode; $object->actionmsg = $actionmsg; $object->actionmsg2 = $actionmsg2; $object->fk_element = $object->id; $object->elementtype = $object->element; // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($db); $result=$interface->run_triggers('PROPAL_SENTBYMAIL',$object,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers if ($error) { dol_print_error($db); } else { // Redirect here // This avoid sending mail twice if going out and then back to page Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg)); exit; } } else { $langs->load("other"); $mesg='
'; if ($mailfile->error) { $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); $mesg.='
'.$mailfile->error; } else { $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; } $mesg.='
'; } } } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').' !
'; dol_syslog('Recipient email is empty'); } } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dol_syslog('Failed to read file: '.$file); } } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")).'
'; dol_syslog('Impossible de lire les donnees de la facture. Le fichier propal n\'a peut-etre pas ete genere.'); } } if ($action == 'modif' && $user->rights->propale->creer) { /* * Repasse la propale en mode brouillon */ $object->fetch($id); $object->fetch_thirdparty(); $object->set_draft($user); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); } if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer) { if ($_POST["remise_id"]) { $object->id=$id; $ret=$object->fetch($id); if ($ret > 0) { $result=$object->insert_discount($_POST["remise_id"]); if ($result < 0) { $mesg='
'.$object->error.'
'; } } else { dol_print_error($db,$object->error); } } } /* * Ajout d'une ligne produit dans la propale */ if ($_POST['action'] == "addline" && $user->rights->propale->creer) { $result=0; if (empty($_POST['idprod']) && $_POST["type"] < 0) { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; $result = -1 ; } if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not '' { $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).'
'; $result = -1 ; } if ($result >= 0 && isset($_POST['qty']) && (($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'])) { $ret=$object->fetch($_POST["id"]); if ($ret < 0) { dol_print_error($db,$object->error); exit; } $ret=$object->fetch_thirdparty(); $price_base_type = 'HT'; // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit if ($_POST['idprod']) { $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); $localtax1_tx= get_localtax($tva_tx, 1, $object->client); //get_default_localtax($mysoc,$object->client,1,$prod->id); $localtax2_tx= get_localtax($tva_tx, 2, $object->client); //get_default_localtax($mysoc,$object->client,2,$prod->id); $tva_npr = get_default_npr($mysoc,$object->client,$prod->id); // On defini prix unitaire if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) { $pu_ht = $prod->multiprices[$object->client->price_level]; $pu_ttc = $prod->multiprices_ttc[$object->client->price_level]; $price_min = $prod->multiprices_min[$object->client->price_level]; $price_base_type = $prod->multiprices_base_type[$object->client->price_level]; } else { $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; $price_min = $prod->price_min; $price_base_type = $prod->price_base_type; } // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($tva_tx != $prod->tva_tx) { if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); } else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } $desc = $prod->description; $desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"
\n":"\n") : ""; $desc.= $_POST['np_desc']; $type = $prod->type; } else { $pu_ht=$_POST['np_price']; $tva_tx=str_replace('*','',$_POST['np_tva_tx']); $tva_npr=preg_match('/\*/',$_POST['np_tva_tx'])?1:0; $desc=$_POST['dp_desc']; $type=$_POST["type"]; $localtax1_tx=get_localtax($tva_tx,1,$object->client); $localtax2_tx=get_localtax($tva_tx,2,$object->client); } $info_bits=0; if ($tva_npr) $info_bits |= 0x01; if ($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) { $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; } else { // Insert line $result=$object->addline( $_POST["id"], $desc, $pu_ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, $_POST['idprod'], $_POST['remise_percent'], $price_base_type, $pu_ttc, $info_bits, $type, -1, 0, $_POST['fk_parent_line'] ); if ($result > 0) { // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); unset($_POST['qty']); unset($_POST['type']); unset($_POST['np_price']); unset($_POST['dp_desc']); unset($_POST['np_tva_tx']); } else { $mesg='
'.$object->error.'
'; } } } } /* * Mise a jour d'une ligne dans la propale */ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST["save"] == $langs->trans("Save")) { if (! $object->fetch($_POST["id"]) > 0) { dol_print_error($db,$object->error); exit; } $object->fetch_thirdparty(); // Define info_bits $info_bits=0; if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01; // Define vat_rate $vat_rate=$_POST['tva_tx']; $vat_rate=str_replace('*','',$vat_rate); $localtax1_rate=get_localtax($vat_rate,1,$object->client); $localtax2_rate=get_localtax($vat_rate,2,$object->client); $up_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice'); // On verifie que le prix minimum est respecte $productid = $_POST['productid'] ; if ($productid) { $product = new Product($db) ; $res=$product->fetch($productid) ; $price_min = $product->price_min; if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level]; } if ($productid && $price_min && (price2num($up_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) { $mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ; } else { $result = $object->updateline($_POST['lineid'], $up_ht, $_POST['qty'], $_POST['remise_percent'], $vat_rate, $localtax1_rate, $localtax2_rate, $_POST['desc'], 'HT', $info_bits, '', $_POST['fk_parent_line'] ); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); } } /* * Generation doc (depuis lien ou depuis cartouche doc) */ if ($action == 'builddoc' && $user->rights->propale->creer) { $object->fetch($id); $object->fetch_thirdparty(); if ($_REQUEST['model']) { $object->setDocModel($user, $_REQUEST['model']); } // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } $result=propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); if ($result <= 0) { dol_print_error($db,$result); exit; } else { Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); exit; } } // Set project if ($_POST['action'] == 'classin') { $object->fetch($id); $object->setProject($_POST['projectid']); } // Delai de livraison if ($_POST["action"] == 'setavailability') { $object->fetch($_REQUEST['id']); $result = $object->availability($_POST['availability_id']); $id=$_REQUEST['id']; } // Origine de la propale if ($_POST["action"] == 'setdemandreason') { $object->fetch($_REQUEST['id']); $result = $object->demand_reason($_POST['demand_reason_id']); $id=$_REQUEST['id']; } // Conditions de reglement if ($_POST["action"] == 'setconditions') { $object->fetch($_REQUEST['id']); $result = $object->cond_reglement($_POST['cond_reglement_id']); $id=$_REQUEST['id']; } if ($action == 'setremisepercent' && $user->rights->propale->creer) { $object->fetch($_REQUEST["id"]); $result = $object->set_remise_percent($user, $_POST['remise_percent']); $id=$_REQUEST["id"]; } if ($action == 'setremiseabsolue' && $user->rights->propale->creer) { $object->fetch($_REQUEST["id"]); $result = $object->set_remise_absolue($user, $_POST['remise_absolue']); $id=$_REQUEST["id"]; } // Mode de reglement if ($_POST["action"] == 'setmode') { $object->fetch($_REQUEST["id"]); $result = $object->mode_reglement($_POST['mode_reglement_id']); $id=$_REQUEST["id"]; } /* * Ordonnancement des lignes */ if ($action == 'up' && $user->rights->propale->creer) { $object->fetch($id); $object->fetch_thirdparty(); $object->line_up(GETPOST('rowid')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); exit; } if ($action == 'down' && $user->rights->propale->creer) { $object->fetch($id); $object->fetch_thirdparty(); $object->line_down(GETPOST('rowid')); // Define output language $outputlangs = $langs; $newlang=''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid')); exit; } /* * View */ llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); $html = new Form($db); $htmlother = new FormOther($db); $formfile = new FormFile($db); $companystatic=new Societe($db); $now=dol_now(); $id = GETPOST('id'); $ref= GETPOST('ref'); if ($id > 0 || ! empty($ref)) { /* * Show object in view mode */ dol_htmloutput_mesg($mesg,$mesgs); $object->fetch($id,$ref); $soc = new Societe($db); $soc->fetch($object->socid); $head = propal_prepare_head($object); dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal'); $formconfirm=''; // Clone confirmation if ($action == 'clone') { // Create an array for form $formquestion=array( //'text' => $langs->trans("ConfirmClone"), //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $html->select_company(GETPOST('socid'),'socid','(s.client=1 OR s.client=3)')) ); // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1); } /* * Confirmation de la suppression de la propale */ if ($action == 'delete') { $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete','',0,1); } /* * Confirmation de la suppression d'une ligne produit/service */ if ($action == 'ask_deleteline') { $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); } /* * Confirmation de la validation de la propale */ if ($action == 'validate') { // on verifie si l'objet est en numerotation provisoire $ref = substr($object->ref, 1, 4); if ($ref == 'PROV') { $numref = $object->getNextNumRef($soc); } else { $numref = $object->ref; } $text=$langs->trans('ConfirmValidateProp',$numref); if ($conf->notification->enabled) { require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php"); $notify=new Notify($db); $text.='
'; $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid); } $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); } // Hook for external modules if (empty($formconfirm) && ! empty($object->hooks)) { foreach($object->hooks as $hook) { if (! empty($hook['modules'])) { foreach($hook['modules'] as $module) { if (empty($formconfirm) && method_exists($module,'formconfirm')) { $formconfirm = $module->formconfirm($action,$object,$lineid); } } } } } // Print form confirm print $formconfirm; print ''; $linkback="".$langs->trans("BackToList").""; // Ref print ''; // Ref client print ''; print ''; $rowspan=11; // Company print ''; print ''; // Ligne info remises tiers print ''; // Date of proposal print ''; print ''; if ($conf->projet->enabled) $rowspan++; if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS) $rowspan++; //Local taxes if ($mysoc->pays_code=='ES') { if($mysoc->localtax1_assuj=="1") $rowspan++; if($mysoc->localtax2_assuj=="1") $rowspan++; } // Notes print ''; print ''; // Date end proposal print ''; print ''; print ''; // Payment term print ''; print ''; // Delivery date $langs->load('deliveries'); print ''; print ''; // Delivery address (deprecated) if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS) { print ''; } // Delivery delay print ''; print ''; // Origin of demand print ''; print ''; // Payment mode print ''; print ''; // Project if ($conf->projet->enabled) { $langs->load("projects"); print ''; } else { print '
'.$langs->trans('Ref').''; print $html->showrefnav($object,'ref',$linkback,1,'ref','ref',''); print '
'; print ''; if ($action != 'refclient' && $object->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Modify')).'
'; print '
'; if ($user->rights->propale->creer && $action == 'refclient') { print '
'; print ''; print ''; print ''; print ' '; print '
'; } else { print $object->ref_client; } print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); print '. '; $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); $absolute_discount=price2num($absolute_discount,'MT'); $absolute_creditnote=price2num($absolute_creditnote,'MT'); if ($absolute_discount) { if ($object->statut > 0) { print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); } else { // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter); } } if ($absolute_creditnote) { print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'. '; } if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'; print ''; if ($action != 'editdate' && $object->brouillon) print ''; print '
'; print $langs->trans('Date'); print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; print '
'; if ($object->brouillon && $action == 'editdate') { print '
'; print ''; print ''; $html->select_date($object->date,'re','','',0,"editdate"); print ''; print '
'; } else { if ($object->date) { print dol_print_date($object->date,'daytext'); } else { print ' '; } } print '
'.$langs->trans('NotePublic').' :
'. nl2br($object->note_public).'
'; print ''; if ($action != 'editecheance' && $object->brouillon) print ''; print '
'; print $langs->trans('DateEndPropal'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($object->brouillon && $action == 'editecheance') { print '
'; print ''; print ''; $html->select_date($object->fin_validite,'ech','','','',"editecheance"); print ''; print '
'; } else { if ($object->fin_validite) { print dol_print_date($object->fin_validite,'daytext'); if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); } else { print ' '; } } print '
'; print ''; if ($action != 'editconditions' && $object->brouillon) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($action == 'editconditions') { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); } else { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); } print '
'; print ''; if ($action != 'editdate_livraison' && $object->brouillon) print ''; print '
'; print $langs->trans('DeliveryDate'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'
'; print '
'; if ($action == 'editdate_livraison') { print '
'; print ''; print ''; $html->select_date($object->date_livraison,'liv_','','','',"editdate_livraison"); print ''; print '
'; } else { print dol_print_date($object->date_livraison,'daytext'); } print '
'; print ''; if ($action != 'editdelivery_address' && $object->brouillon) print ''; print '
'; print $langs->trans('DeliveryAddress'); print 'socid.'&id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; print '
'; if ($action == 'editdelivery_address') { $html->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid'),'fk_address','propal',$object->id); } else { $html->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid'),'none','propal',$object->id); } print '
'; print ''; if ($action != 'editavailability' && $object->brouillon) print ''; print '
'; print $langs->trans('AvailabilityPeriod'); if ($conf->commande->enabled) print ' ('.$langs->trans('AfterOrder').')'; print 'id.'">'.img_edit($langs->trans('SetAvailability'),1).'
'; print '
'; if ($action == 'editavailability') { $html->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1); } else { $html->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1); } print '
'; print ''; if ($action != 'editdemandreason' && $object->brouillon) print ''; print '
'; print $langs->trans('Source'); print 'id.'">'.img_edit($langs->trans('SetDemandReason'),1).'
'; print '
'; //print $object->demand_reason_id; if ($action == 'editdemandreason') { $html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1); } else { $html->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none'); } print '
'; print ''; if ($action != 'editmode' && $object->brouillon) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($action == 'editmode') { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); } print '
'; print ''; if ($user->rights->propale->creer) { if ($action != 'classer') print ''; print '
'; print $langs->trans('Project').''.img_edit($langs->trans('SetProject')).'
'; print '
'; if ($action == 'classer') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none'); } print '
'; if (!empty($object->fk_project)) { print ''; $proj = new Project($db); $proj->fetch($object->fk_project); print ''; print $proj->ref; print ''; print ''; } else { print ' '; } } print ''; } // Amount HT print ''.$langs->trans('AmountHT').''; print ''.price($object->total_ht).''; print ''.$langs->trans("Currency".$conf->monnaie).''; // Amount VAT print ''.$langs->trans('AmountVAT').''; print ''.price($object->total_tva).''; print ''.$langs->trans("Currency".$conf->monnaie).''; // Amount Local Taxes if ($mysoc->pays_code=='ES') { if ($mysoc->localtax1_assuj=="1") //Localtax1 RE { print ''.$langs->transcountry("AmountLT1",$mysoc->pays_code).''; print ''.price($object->total_localtax1).''; print ''.$langs->trans("Currency".$conf->monnaie).''; } if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF { print ''.$langs->transcountry("AmountLT2",$mysoc->pays_code).''; print ''.price($object->total_localtax2).''; print ''.$langs->trans("Currency".$conf->monnaie).''; } } // Amount TTC print ''.$langs->trans('AmountTTC').''; print ''.price($object->total_ttc).''; print ''.$langs->trans("Currency".$conf->monnaie).''; // Statut print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; print '
'; /* * Lines */ $result = $object->getLinesArray(); if ($conf->use_javascript_ajax && $object->statut == 0) { include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'); } // TODO test using div instead of tables //print '
'; print ''; // Show object lines if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid); //print '
'; /* * Form to add new line */ if ($object->statut == 0 && $user->rights->propale->creer) { if ($action != 'editline') { $var=true; // Add free products/services $object->formAddFreeProduct(0,$mysoc,$soc); // Add predefined products/services if ($conf->product->enabled || $conf->service->enabled) { $var=!$var; $object->formAddPredefinedProduct(0,$mysoc,$soc); } // Hook for external modules foreach($object->hooks as $hook) { if (! empty($hook['modules'])) { foreach($hook['modules'] as $module) { if (method_exists($module,'formAddObject')) { $var=!$var; $module->formAddObject($object); } } } } } } // TODO test using div instead of tables print '
'; //print '
'; print ''; print "\n"; if ($action == 'statut') { /* * Formulaire cloture (signe ou non) */ $form_close = '
'; $form_close.= ''; $form_close.= ''; $form_close.= ''; $form_close.= ''; $form_close.= ''; $form_close.= '
'.$langs->trans("CloseAs").''; $form_close.= ''; $form_close.= ''; $form_close.= '
'.$langs->trans('Note').'
'; $form_close.= ''; $form_close.= '   '; $form_close.= ' '; $form_close.= '
'; print $form_close; } /* * Boutons Actions */ if ($action != 'presend') { print '
'; if ($action != 'statut' && $action <> 'editline') { // Validate if ($object->statut == 0 && $user->rights->propale->valider) { if (sizeof($object->lines) > 0) print ''.$langs->trans('Validate').''; else print ''.$langs->trans('Validate').''; } // Edit if ($object->statut == 1 && $user->rights->propale->creer) { print ''.$langs->trans('Modify').''; } // Send if ($object->statut == 1) { $propref = dol_sanitizeFileName($object->ref); $file = $conf->propale->dir_output . '/'.$propref.'/'.$propref.'.pdf'; if (file_exists($file)) { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send) { print ''.$langs->trans('SendByMail').''; } else print ''.$langs->trans('SendByMail').''; } } // Create an order if ($conf->commande->enabled && $object->statut == 2 && $user->societe_id == 0) { if ($user->rights->commande->creer) { print ''.$langs->trans("AddOrder").''; } } // Create an invoice and classify billed if ($conf->facture->enabled && $object->statut == 2 && $user->societe_id == 0) { if ($user->rights->facture->creer) { print ''.$langs->trans("AddBill").''; } $arraypropal=$object->getInvoiceArrayList(); if (is_array($arraypropal) && sizeof($arraypropal) > 0) { print 'socid.'">'.$langs->trans("ClassifyBilled").''; } } // Close if ($object->statut == 1 && $user->rights->propale->cloturer) { print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; print '>'.$langs->trans('Close').''; } // Clone if ($object->type == 0 && $user->rights->propale->creer) { print ''.$langs->trans("ToClone").''; } // Delete if ($user->rights->propale->supprimer) { print ''.$langs->trans('Delete').''; } } print '
'; print "
\n"; } if ($action != 'presend') { print '
'; print ''; // ancre /* * Documents generes */ $filename=dol_sanitizeFileName($object->ref); $filedir=$conf->propale->dir_output . "/" . dol_sanitizeFileName($object->ref); $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=$user->rights->propale->creer; $delallowed=$user->rights->propale->supprimer; $var=true; $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'',0,'',$soc->default_lang,$object->hooks); /* * Linked object block */ $somethingshown=$object->showLinkedObjectBlock(); print ''; // List of actions on element include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); $formactions=new FormActions($db); $somethingshown=$formactions->showactions($object,'propal',$socid); print '
'; } /* * Action presend * */ if ($action == 'presend') { $ref = dol_sanitizeFileName($object->ref); $file = $conf->propale->dir_output . '/' . $ref . '/' . $ref . '.pdf'; print '
'; print_titre($langs->trans('SendPropalByMail')); // Create form object include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'); $formmail = new FormMail($db); $formmail->fromtype = 'user'; $formmail->fromid = $user->id; $formmail->fromname = $user->getFullName($langs); $formmail->frommail = $user->email; $formmail->withfrom=1; $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; $formmail->withtosocid=$soc->id; $formmail->withtocc=1; $formmail->withtoccsocid=0; $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; $formmail->withtocccsocid=0; $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__'); $formmail->withfile=2; $formmail->withbody=1; $formmail->withdeliveryreceipt=1; $formmail->withcancel=1; // Tableau des substitutions $formmail->substit['__PROPREF__']=$object->ref; // Tableau des parametres complementaires $formmail->param['action']='send'; $formmail->param['models']='propal_send'; $formmail->param['id']=$object->id; $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; // Init list of files if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') { $formmail->clear_attached_files(); $formmail->add_attached_files($file,dol_sanitizeFilename($object->ref).'.pdf','application/pdf'); } $formmail->show_form(); print '
'; } } else { /**************************************************************************** * * * Mode Liste des propales * * * ****************************************************************************/ $now=dol_now(); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $viewstatut=$db->escape(GETPOST('viewstatut')); $object_statut = $db->escape(GETPOST('propal_statut')); if($object_statut != '') $viewstatut=$object_statut; if (! $sortfield) $sortfield='p.datep'; if (! $sortorder) $sortorder='DESC'; $limit = $conf->liste_limit; $sql = 'SELECT s.nom, s.rowid, s.client, '; $sql.= 'p.rowid as propalid, p.total_ht, p.ref, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,'; if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,"; $sql.= ' u.login'; $sql.= ' FROM ('.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p'; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ')'; if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid'; $sql.= ' WHERE p.fk_soc = s.rowid'; $sql.= ' AND s.entity = '.$conf->entity; if (!$user->rights->societe->client->voir && !$socid) //restriction { $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; } if (GETPOST('search_ref')) { $sql.= " AND p.ref LIKE '%".$db->escape(GETPOST('search_ref'))."%'"; } if (!empty($_GET['search_societe'])) { $sql.= " AND s.nom LIKE '%".$db->escape(GETPOST('search_societe'))."%'"; } if (!empty($_GET['search_montant_ht'])) { $sql.= " AND p.total_ht='".$db->escape(GETPOST('search_montant_ht'))."'"; } if ($sall) $sql.= " AND (s.nom like '%".$db->escape($sall)."%' OR p.note like '%".$db->escape($sall)."%' OR pd.description like '%".$db->escape($sall)."%')"; if ($socid) $sql.= ' AND s.rowid = '.$socid; if ($viewstatut <> '') { $sql.= ' AND p.fk_statut in ('.$viewstatut.')'; } if ($month > 0) { if ($year > 0) $sql.= " AND date_format(p.datep, '%Y-%m') = '".$year."-".$month."'"; else $sql.= " AND date_format(p.datep, '%m') = '".$month."'"; } if ($year > 0) { $sql.= " AND date_format(p.datep, '%Y') = '".$year."'"; } if (dol_strlen($_POST['sf_ref']) > 0) { $sql.= " AND p.ref like '%".$db->escape($_POST["sf_ref"]) . "%'"; } $sql.= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC'; $sql.= $db->plimit($limit + 1,$offset); $result=$db->query($sql); if ($result) { $objectstatic=new Propal($db); $userstatic=new User($db); $num = $db->num_rows($result); if ($socid) { $soc = new Societe($db); $soc->fetch($socid); } $param='&socid='.$socid.'&viewstatut='.$viewstatut; if ($month) $param.='&month='.$month; if ($year) $param.='&year='.$year; print_barre_liste($langs->trans('ListOfProposals').' '.($socid?'- '.$soc->nom:''), $page,'propal.php',$param,$sortfield,$sortorder,'',$num); $i = 0; print ''; print ''; print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','',$param, 'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','',$param, 'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.total_ht','',$param, 'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Author'),$_SERVER["PHP_SELF"],'u.login','',$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','',$param,'align="right"',$sortfield,$sortorder); print ''; print "\n"; // Lignes des champs de filtre print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; $var=true; while ($i < min($num,$limit)) { $objp = $db->fetch_object($result); $now = time(); $var=!$var; print ''; print ''; // Date propale print '\n"; // Date fin validite if ($objp->dfv) { print ''; } else { print ''; } print '\n"; $userstatic->id=$objp->fk_user_author; $userstatic->login=$objp->login; print '\n"; print '\n"; print ''; print "\n"; $total = $total + $objp->total_ht; $subtotal = $subtotal + $objp->total_ht; $i++; } print '
 
'; print ''; print ''; print ''; print ''; print $langs->trans('Month').': '; print ' '.$langs->trans('Year').': '; $syear = $year; //if($syear == '') $syear = date("Y"); $htmlother->select_year($syear,'year',1, 20, 5); print ' '; print ''; print ' '; $html->select_propal_statut($viewstatut); print ''; print '
'; $objectstatic->id=$objp->propalid; $objectstatic->ref=$objp->ref; print ''; print ''; print ''; print '
'; print $objectstatic->getNomUrl(1); print ''; if ($objp->fk_statut == 1 && $objp->dfv < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); print ''; $filename=dol_sanitizeFileName($objp->ref); $filedir=$conf->propale->dir_output . '/' . dol_sanitizeFileName($objp->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->propalid; $formfile->show_documents('propal',$filename,$filedir,$urlsource,'','','',1,'',1); print '
'; if ($objp->client == 1) { $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->rowid; } else { $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->rowid; } // Company $companystatic->id=$objp->rowid; $companystatic->nom=$objp->nom; $companystatic->client=$objp->client; print '
'; print $companystatic->getNomUrl(1,'customer'); print ''; $y = dol_print_date($db->jdate($objp->dp),'%Y'); $m = dol_print_date($db->jdate($objp->dp),'%m'); $mt= dol_print_date($db->jdate($objp->dp),'%b'); $d = dol_print_date($db->jdate($objp->dp),'%d'); print $d."\n"; print ' '; print $mt."\n"; print ' '; print $y."'.dol_print_date($db->jdate($objp->dfv),'day'); print ' '.price($objp->total_ht)."'; if ($userstatic->id) print $userstatic->getLoginUrl(1); else print ' '; print "'.$objectstatic->LibStatut($objp->fk_statut,5)." 
'; $db->free($result); } else { dol_print_error($db); } } $db->close(); llxFooter('$Date: 2011/08/03 00:46:26 $ - $Revision: 1.614 $'); ?>