diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php index 832885b0f8c..84987129be3 100644 --- a/htdocs/comm/fiche.php +++ b/htdocs/comm/fiche.php @@ -742,7 +742,7 @@ if ($id > 0) if (! empty($conf->propal->enabled) && $user->rights->propal->creer) { $langs->load("propal"); - print ''.$langs->trans("AddProp").''; + print ''.$langs->trans("AddProp").''; } if (! empty($conf->commande->enabled) && $user->rights->commande->creer) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 31c9e36d898..cd2f44878ed 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -5,7 +5,7 @@ * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2010-2011 Philippe Grand * Copyright (C) 2012 Christophe Battarel * @@ -38,7 +38,11 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +if (! empty($conf->projet->enabled)) +{ + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; +} $langs->load('companies'); $langs->load('propal'); @@ -46,6 +50,7 @@ $langs->load('compta'); $langs->load('bills'); $langs->load('orders'); $langs->load('products'); +$langs->load("deliveries"); if (! empty($conf->margin->enabled)) $langs->load('margins'); @@ -55,6 +60,8 @@ $id=GETPOST('id','int'); $ref=GETPOST('ref','alpha'); $socid=GETPOST('socid','int'); $action=GETPOST('action','alpha'); +$origin=GETPOST('origin','alpha'); +$originid=GETPOST('originid','int'); $confirm=GETPOST('confirm','alpha'); $lineid=GETPOST('lineid','int'); @@ -72,30 +79,12 @@ $result = restrictedArea($user, 'propal', $id); $object = new Propal($db); +// Load object // Load object if ($id > 0 || ! empty($ref)) { - if ($action != 'add') - { - $ret=$object->fetch($id, $ref); - if ($ret == 0) - { - $langs->load("errors"); - setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors'); - $error++; - } - else if ($ret < 0) - { - setEventMessage($object->error, 'errors'); - $error++; - } - else $object->fetch_thirdparty(); - } -} -else -{ - header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); - exit; + $ret=$object->fetch($id, $ref); + $ret=$object->fetch_thirdparty(); } // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -262,14 +251,21 @@ else if ($action == 'add' && $user->rights->propal->creer) if (empty($datep)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors'); - header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); - exit; + $action='create'; + $error++; } if (empty($duration)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ValidityDuration")), 'errors'); - header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create'); - exit; + $action='create'; + $error++; + } + + if ($socid<1) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Customer")),'errors'); + $action='create'; + $error++; } if (! $error) @@ -1174,731 +1170,1022 @@ $companystatic=new Societe($db); $now=dol_now(); -/* - * Show object in view mode - */ - -$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') +// Add new proposal +if ($action == 'create') { - // 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' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)')) - ); - // Paiement incomplet. On demande si motif = escompte ou autre - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1); -} + print_fiche_titre($langs->trans("NewProp")); + + $soc = new Societe($db); + if ($socid>0) $res=$soc->fetch($socid); -// Confirm delete -else if ($action == 'delete') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1); -} + $object = new Propal($db); -// Confirm reopen -else if ($action == 'reopen') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1); -} - -// Confirmation delete product/service line -else if ($action == 'ask_deleteline') -{ - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); -} - -// Confirm validate proposal -else if ($action == 'validate') -{ - $error=0; - - // on verifie si l'objet est en numerotation provisoire - $ref = substr($object->ref, 1, 4); - if ($ref == 'PROV') + $numpr=''; + $obj = $conf->global->PROPALE_ADDON; + if ($obj) { - $numref = $object->getNextNumRef($soc); - if (empty($numref)) + if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php")) { - $error++; - dol_htmloutput_errors($object->error); + require_once DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.'.php'; + $modPropale = new $obj; + $numpr = $modPropale->getNextValue($soc,$object); } } - else + + // Fix pour modele numerotation qui deconne + // Si numero deja pris (ne devrait pas arriver), on incremente par .num+1 + $sql = "SELECT count(*) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."propal"; + $sql.= " WHERE ref LIKE '".$numpr."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) { - $numref = $object->ref; - } - - $text=$langs->trans('ConfirmValidateProp',$numref); - if (! empty($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); - } - - if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); -} - -if (! $formconfirm) -{ - $parameters=array('lineid'=>$lineid); - $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook -} - -// Print form confirm -print $formconfirm; - - -print ''; - -$linkback = ''.$langs->trans("BackToList").''; - -// Ref -print ''; - -// Ref client -print ''; -print ''; - -// Company -print ''; -print ''; - -// Ligne info remises tiers -print ''; - -// Date of proposal -print ''; -print ''; - -// Date end proposal -print ''; -print ''; -print ''; - -// Payment term -print ''; -print ''; - -// Delivery date -$langs->load('deliveries'); -print ''; -print ''; - -// Delivery delay -print ''; -print ''; - -// Origin of demand -print ''; -print ''; - -// Payment mode -print ''; -print ''; - -// Project -if (! empty($conf->projet->enabled)) -{ - $langs->load("projects"); - print '
'.$langs->trans('Ref').''; -print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); -print '
'; -print ''; -if ($action != 'refclient' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('RefCustomer').''; -print ''.img_edit($langs->trans('Modify')).'
'; -print '
'; -if ($user->rights->propal->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->currency)); - } - else - { - // Remise dispo de type non avoir - $filter='fk_facture_source IS NULL'; - print '
'; - $form->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->currency)).'. '; -} -if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; -print '
'; -print ''; -if ($action != 'editdate' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('Date'); -print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; -print '
'; -if (! empty($object->brouillon) && $action == 'editdate') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->date,'re','','',0,"editdate"); - print ''; - print '
'; -} -else -{ - if ($object->date) - { - print dol_print_date($object->date,'daytext'); - } - else - { - print ' '; - } -} -print '
'; -print ''; -if ($action != 'editecheance' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('DateEndPropal'); -print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; -print '
'; -if (! empty($object->brouillon) && $action == 'editecheance') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->fin_validite,'ech','','','',"editecheance"); - print ''; - print '
'; -} -else -{ - if (! empty($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' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('PaymentConditionsShort'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'
'; -print '
'; -if ($action == 'editconditions') -{ - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); -} -else -{ - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); -} -print '
'; -print ''; -if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('DeliveryDate'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'
'; -print '
'; -if ($action == 'editdate_livraison') -{ - print '
'; - print ''; - print ''; - $form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison"); - print ''; - print '
'; -} -else -{ - print dol_print_date($object->date_livraison,'daytext'); -} -print '
'; -print ''; -if ($action != 'editavailability' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('AvailabilityPeriod'); -if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')'; -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'
'; -print '
'; -if ($action == 'editavailability') -{ - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1); -} -else -{ - $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1); -} - -print '
'; -print ''; -if ($action != 'editdemandreason' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('Source'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'
'; -print '
'; -//print $object->demand_reason_id; -if ($action == 'editdemandreason') -{ - $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1); -} -else -{ - $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none'); -} - -print '
'; -print ''; -if ($action != 'editmode' && ! empty($object->brouillon)) print ''; -print '
'; -print $langs->trans('PaymentMode'); -print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'
'; -print '
'; -if ($action == 'editmode') -{ - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); -} -else -{ - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); -} -print '
'; - print ''; - if ($user->rights->propal->creer) - { - if ($action != 'classify') print ''; - print '
'; - print $langs->trans('Project').''.img_edit($langs->transnoentitiesnoconv('SetProject')).'
'; - print '
'; - if ($action == 'classify') + $obj=$db->fetch_object($resql); + $num = $obj->nb; + $db->free($resql); + if ($num > 0) { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); + $numpr .= "." . ($num + 1); + } + } + + print '
'; + print ''; + print ''; + + if ($origin != 'project' && $originid) + { + print ''; + print ''; + } + + print ''; + + // Ref + print ''; + print ''; + print ''; + print ''; + + // Ref customer + print ''; + print ''; + + // Third party + print ''; + print ''; + if($socid>0) + { + print ''; + } + else + { + print ''; + } + print ''."\n"; + + // Contacts + if($socid>0) + { + print "'; + + // Ligne info remises tiers + print ''; + } + + // Date + print ''; + + // Validaty duration + print ''; + + // Terms of payment + print ''; + + // Mode of payment + print ''; + + // What trigger creation + print ''; + + // Delivery delay + print ''; + + // Delivery date (or manufacturing) + print ''; + print ''; + + // Model + print ''; + print ''; + print '"; + + // Project + if (! empty($conf->projet->enabled) && $socid>0) + { + $projectid = 0; + if ($origin == 'project') $projectid = ($originid?$originid:0); + + print ''; + print ''; + print ''; + } + + // Other attributes + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook) && ! empty($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''."\n"; + } + } + + print "
'.$langs->trans("Ref").''.$numpr.'
'.$langs->trans('RefCustomer').''; + print '
'.$langs->trans('Customer').''; + print $soc->getNomUrl(1); + print ''; + print ''; + print $form->select_company('','socid','s.client = 1',1); + print '
".$langs->trans("DefaultContact").''; + $form->select_contacts($soc->id,$setcontact,'contactidp',1,$srccontactslist); + print '
'.$langs->trans('Discounts').''; + if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$soc->getAvailableDiscounts(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print '
'.$langs->trans('Date').''; + $form->select_date('','','','','',"addprop"); + print '
'.$langs->trans("ValidityDuration").' '.$langs->trans("days").'
'.$langs->trans('PaymentConditionsShort').''; + $form->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id'); + print '
'.$langs->trans('PaymentMode').''; + $form->select_types_paiements($soc->mode_reglement,'mode_reglement_id'); + print '
'.$langs->trans('Source').''; + $form->select_demand_reason('','demand_reason_id',"SRC_PROP",1); + print '
'.$langs->trans('AvailabilityPeriod').''; + $form->select_availability('','availability_id','',1); + print '
'.$langs->trans("DeliveryDate").''; + if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "") + { + $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); + $syear = date("Y", $tmpdte); + $smonth = date("m", $tmpdte); + $sday = date("d", $tmpdte); + $form->select_date($syear."-".$smonth."-".$sday,'liv_','','','',"addprop"); + } + else + { + $datepropal=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; + $form->select_date($datepropal,'liv_','','','',"addprop"); + } + print '
'.$langs->trans("DefaultModel").''; + $liste=ModelePDFPropales::liste_modeles($db); + print $form->selectarray('model',$liste,$conf->global->PROPALE_ADDON_PDF); + print "
'.$langs->trans("Project").''; + + $numprojet=select_projects($soc->id,$projectid); + if ($numprojet==0) + { + print '   '.$langs->trans("AddProject").''; + } + print '
'; + print $extrafields->showInputField($key,$value); + print '
"; + print '
'; + + /* + * Combobox pour la fonction de copie + */ + + if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) + { + print ''; + } + + print ''; + if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE)) + { + // For backward compatibility + print ''; + print ''; + print ''; + print ''; + + if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) print ''; + + print ''; + print ''; + } + + if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) + { + print ''; } - else + print '
'.$langs->trans("CopyPropalFrom").' '; + $liste_propal = array(); + $liste_propal[0] = ''; + + $sql ="SELECT p.rowid as id, p.ref, s.nom"; + $sql.=" FROM ".MAIN_DB_PREFIX."propal p"; + $sql.= ", ".MAIN_DB_PREFIX."societe s"; + $sql.= " WHERE s.rowid = p.fk_soc"; + $sql.= " AND p.entity = ".$conf->entity; + $sql.= " AND p.fk_statut <> 0"; + $sql.= " ORDER BY Id"; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $propalRefAndSocName = $row[1]." - ".$row[2]; + $liste_propal[$row[0]]=$propalRefAndSocName; + $i++; + } + print $form->selectarray("copie_propal",$liste_propal, 0); } else { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none'); + dol_print_error($db); + } + print '
 
'.$langs->trans("CreateEmptyPropal").'
'; + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) + { + $lib=$langs->trans("ProductsAndServices"); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++) + { + print ''; + print ''; + print ''; + print ''; + } + + print "
'.$lib.''.$langs->trans("Qty").''.$langs->trans("ReductionShort").'
'; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) + $form->select_produits('',"idprod".$i,'',$conf->product->limit_size,$soc->price_level); + else + $form->select_produits('',"idprod".$i,'',$conf->product->limit_size); + print '%
"; + } print '
'; + print '
'; + + $langs->load("bills"); + print '
'; + print ''; + print ' '; + print '
'; + + print "
"; +} +else +{ + /* + * Show object in view mode + */ + + $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') { - print '
'; - if (! empty($object->fk_project)) - { - print ''; - $proj = new Project($db); - $proj->fetch($object->fk_project); - print ''; - print $proj->ref; - print ''; - print ''; - } - else { - print ' '; - } + // 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' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)')) + ); + // Paiement incomplet. On demande si motif = escompte ou autre + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1); } - print ''; -} - -// Other attributes -$parameters=array('colspan' => ' colspan="3"'); -$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook -if (empty($reshook) && ! empty($extrafields->attribute_label)) -{ - foreach($extrafields->attribute_label as $key=>$label) - { - $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); - print 'attribute_required[$key])) print ' class="fieldrequired"'; - print '>'.$label.''; - print $extrafields->showInputField($key,$value); - print ''."\n"; - } -} - -// Amount HT -print ''.$langs->trans('AmountHT').''; -print ''.price($object->total_ht).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Margin Infos -if (! empty($conf->margin->enabled)) { - print ''; - $object->displayMarginInfos(); - print ''; -} -print ''; - -// Amount VAT -print ''.$langs->trans('AmountVAT').''; -print ''.price($object->total_tva).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Amount Local Taxes -if ($mysoc->localtax1_assuj=="1") //Localtax1 -{ - print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).''; - print ''.price($object->total_localtax1).''; - print ''.$langs->trans("Currency".$conf->currency).''; -} -if ($mysoc->localtax2_assuj=="1") //Localtax2 -{ - print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).''; - print ''.price($object->total_localtax2).''; - print ''.$langs->trans("Currency".$conf->currency).''; -} - - -// Amount TTC -print ''.$langs->trans('AmountTTC').''; -print ''.price($object->total_ttc).''; -print ''.$langs->trans("Currency".$conf->currency).''; - -// Statut -print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; - -print '
'; - -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) -{ - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; -} - -if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) -{ - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; -} - -/* - * Lines - */ - -if (! empty($conf->use_javascript_ajax) && $object->statut == 0) -{ - include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; -} - -print ''; - -// Show object lines -$result = $object->getLinesArray(); -if (! empty($object->lines)) - $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid); - -// Form to add new line -if ($object->statut == 0 && $user->rights->propal->creer) -{ - if ($action != 'editline') + + // Confirm delete + else if ($action == 'delete') { - $var=true; - - if ($conf->global->MAIN_FEATURES_LEVEL > 1) + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1); + } + + // Confirm reopen + else if ($action == 'reopen') + { + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1); + } + + // Confirmation delete product/service line + else if ($action == 'ask_deleteline') + { + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); + } + + // Confirm validate proposal + else if ($action == 'validate') + { + $error=0; + + // on verifie si l'objet est en numerotation provisoire + $ref = substr($object->ref, 1, 4); + if ($ref == 'PROV') { - // Add free or predefined products/services - $object->formAddObjectLine(0,$mysoc,$soc); + $numref = $object->getNextNumRef($soc); + if (empty($numref)) + { + $error++; + dol_htmloutput_errors($object->error); + } } else { - // Add free products/services - $object->formAddFreeProduct(0,$mysoc,$soc); - - // Add predefined products/services - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) - { - $var=!$var; - $object->formAddPredefinedProduct(0,$mysoc,$soc); - } + $numref = $object->ref; } - - $parameters=array(); - $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + $text=$langs->trans('ConfirmValidateProp',$numref); + if (! empty($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); + } + + if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1); } -} - -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') + + if (! $formconfirm) { - // Validate - if ($object->statut == 0 && $user->rights->propal->valider) + $parameters=array('lineid'=>$lineid); + $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + } + + // Print form confirm + print $formconfirm; + + + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + // Ref client + print ''; + print ''; + + // Company + print ''; + print ''; + + // Ligne info remises tiers + print ''; + + // Date of proposal + print ''; + print ''; + + // Date end proposal + print ''; + print ''; + print ''; + + // Payment term + print ''; + print ''; + + // Delivery date + $langs->load('deliveries'); + print ''; + print ''; + + // Delivery delay + print ''; + print ''; + + // Origin of demand + print ''; + print ''; + + // Payment mode + print ''; + print ''; + + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + print ''; } - - // Delete - if ($user->rights->propal->supprimer) + else { - print ''.$langs->trans('Delete').''; + print '
'.$langs->trans('Ref').''; + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); + print '
'; + print ''; + if ($action != 'refclient' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('RefCustomer').''; + print ''.img_edit($langs->trans('Modify')).'
'; + print '
'; + if ($user->rights->propal->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) { - if (count($object->lines) > 0) print ''.$langs->trans('Validate').''; - else print ''.$langs->trans('Validate').''; + print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency)); } - - // Edit - if ($object->statut == 1 && $user->rights->propal->creer) + else { - print ''.$langs->trans('Modify').''; + // Remise dispo de type non avoir + $filter='fk_facture_source IS NULL'; + print '
'; + $form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter); } - - // ReOpen - if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) + } + if ($absolute_creditnote) + { + print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. '; + } + if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; + print '
'; + print ''; + if ($action != 'editdate' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('Date'); + print 'id.'">'.img_edit($langs->trans('SetDate'),1).'
'; + print '
'; + if (! empty($object->brouillon) && $action == 'editdate') + { + print '
'; + print ''; + print ''; + $form->select_date($object->date,'re','','',0,"editdate"); + print ''; + print '
'; + } + else + { + if ($object->date) { - print 'global->MAIN_JUMP_TAG)?'':'#reopen').'"'; - print '>'.$langs->trans('ReOpen').''; + print dol_print_date($object->date,'daytext'); } - - // Send - if ($object->statut == 1 || $object->statut == 2) + else { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; + print ' '; } - - // Create an order - if (! empty($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 ($object->statut == 2 && $user->societe_id == 0) + } + print '
'; + print ''; + if ($action != 'editecheance' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('DateEndPropal'); + print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print '
'; + if (! empty($object->brouillon) && $action == 'editecheance') + { + print '
'; + print ''; + print ''; + $form->select_date($object->fin_validite,'ech','','','',"editecheance"); + print ''; + print '
'; + } + else + { + if (! empty($object->fin_validite)) { - if (! empty($conf->facture->enabled) && $user->rights->facture->creer) - { - print ''.$langs->trans("AddBill").''; - } - - $arraypropal=$object->getInvoiceArrayList(); - if (is_array($arraypropal) && count($arraypropal) > 0) - { - print 'socid.'">'.$langs->trans("ClassifyBilled").''; - } + 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")); } - - // Close - if ($object->statut == 1 && $user->rights->propal->cloturer) + else { - print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; - print '>'.$langs->trans('Close').''; + print ' '; } - - // Clone + } + print '
'; + print ''; + if ($action != 'editconditions' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'
'; + print '
'; + if ($action == 'editconditions') + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); + } + else + { + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); + } + print '
'; + print ''; + if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('DeliveryDate'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'
'; + print '
'; + if ($action == 'editdate_livraison') + { + print '
'; + print ''; + print ''; + $form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison"); + print ''; + print '
'; + } + else + { + print dol_print_date($object->date_livraison,'daytext'); + } + print '
'; + print ''; + if ($action != 'editavailability' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('AvailabilityPeriod'); + if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')'; + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'
'; + print '
'; + if ($action == 'editavailability') + { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1); + } + else + { + $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1); + } + + print '
'; + print ''; + if ($action != 'editdemandreason' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('Source'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'
'; + print '
'; + //print $object->demand_reason_id; + if ($action == 'editdemandreason') + { + $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1); + } + else + { + $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none'); + } + + print '
'; + print ''; + if ($action != 'editmode' && ! empty($object->brouillon)) print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'
'; + print '
'; + if ($action == 'editmode') + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); + } + else + { + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); + } + print '
'; + print ''; if ($user->rights->propal->creer) { - print ''.$langs->trans("ToClone").''; + if ($action != 'classify') print ''; + print '
'; + print $langs->trans('Project').''.img_edit($langs->transnoentitiesnoconv('SetProject')).'
'; + print '
'; + if ($action == 'classify') + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); + } + else + { + $form->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 ''; } - - print '
'; - print "
\n"; -} - -if ($action != 'presend') -{ - print '
'; - print ''; // ancre - - - /* - * Documents generes - */ - $filename=dol_sanitizeFileName($object->ref); - $filedir=$conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); - $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed=$user->rights->propal->creer; - $delallowed=$user->rights->propal->supprimer; - - $var=true; - - $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'',0,'',$soc->default_lang); - - - /* - * 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); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($object->ref,'/')); - $file=$fileparams['fullname']; - - // Build document if it not exists - if (! $file || ! is_readable($file)) - { - // 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, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($object->ref,'/')); - $file=$fileparams['fullname']; - } - - 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=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false); - $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; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - // 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 (GETPOST("mode")=='init') + + // Other attributes + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + if (empty($reshook) && ! empty($extrafields->attribute_label)) { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); + foreach($extrafields->attribute_label as $key=>$label) + { + $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); + print 'attribute_required[$key])) print ' class="fieldrequired"'; + print '>'.$label.''; + print $extrafields->showInputField($key,$value); + print ''."\n"; + } + } + + // Amount HT + print ''.$langs->trans('AmountHT').''; + print ''.price($object->total_ht).''; + print ''.$langs->trans("Currency".$conf->currency).''; + + // Margin Infos + if (! empty($conf->margin->enabled)) { + print ''; + $object->displayMarginInfos(); + print ''; + } + print ''; + + // Amount VAT + print ''.$langs->trans('AmountVAT').''; + print ''.price($object->total_tva).''; + print ''.$langs->trans("Currency".$conf->currency).''; + + // Amount Local Taxes + if ($mysoc->localtax1_assuj=="1") //Localtax1 + { + print ''.$langs->transcountry("AmountLT1",$mysoc->country_code).''; + print ''.price($object->total_localtax1).''; + print ''.$langs->trans("Currency".$conf->currency).''; + } + if ($mysoc->localtax2_assuj=="1") //Localtax2 + { + print ''.$langs->transcountry("AmountLT2",$mysoc->country_code).''; + print ''.price($object->total_localtax2).''; + print ''.$langs->trans("Currency".$conf->currency).''; + } + + + // Amount TTC + print ''.$langs->trans('AmountTTC').''; + print ''.price($object->total_ttc).''; + print ''.$langs->trans("Currency".$conf->currency).''; + + // Statut + print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; + + print '
'; + + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) + { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + /* + * Lines + */ + + if (! empty($conf->use_javascript_ajax) && $object->statut == 0) + { + include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'; + } + + print ''; + + // Show object lines + $result = $object->getLinesArray(); + if (! empty($object->lines)) + $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid); + + // Form to add new line + if ($object->statut == 0 && $user->rights->propal->creer) + { + if ($action != 'editline') + { + $var=true; + + if ($conf->global->MAIN_FEATURES_LEVEL > 1) + { + // Add free or predefined products/services + $object->formAddObjectLine(0,$mysoc,$soc); + } + else + { + // Add free products/services + $object->formAddFreeProduct(0,$mysoc,$soc); + + // Add predefined products/services + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) + { + $var=!$var; + $object->formAddPredefinedProduct(0,$mysoc,$soc); + } + } + + $parameters=array(); + $reshook=$hookmanager->executeHooks('formAddObjectLine',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + } + } + + 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->propal->valider) + { + if (count($object->lines) > 0) print ''.$langs->trans('Validate').''; + else print ''.$langs->trans('Validate').''; + } + + // Edit + if ($object->statut == 1 && $user->rights->propal->creer) + { + print ''.$langs->trans('Modify').''; + } + + // ReOpen + if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) + { + print 'global->MAIN_JUMP_TAG)?'':'#reopen').'"'; + print '>'.$langs->trans('ReOpen').''; + } + + // Send + if ($object->statut == 1 || $object->statut == 2) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) + { + print ''.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; + } + + // Create an order + if (! empty($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 ($object->statut == 2 && $user->societe_id == 0) + { + if (! empty($conf->facture->enabled) && $user->rights->facture->creer) + { + print ''.$langs->trans("AddBill").''; + } + + $arraypropal=$object->getInvoiceArrayList(); + if (is_array($arraypropal) && count($arraypropal) > 0) + { + print 'socid.'">'.$langs->trans("ClassifyBilled").''; + } + } + + // Close + if ($object->statut == 1 && $user->rights->propal->cloturer) + { + print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; + print '>'.$langs->trans('Close').''; + } + + // Clone + if ($user->rights->propal->creer) + { + print ''.$langs->trans("ToClone").''; + } + + // Delete + if ($user->rights->propal->supprimer) + { + print ''.$langs->trans('Delete').''; + } + + } + + print '
'; + print "
\n"; + } + + if ($action != 'presend') + { + print '
'; + print ''; // ancre + + + /* + * Documents generes + */ + $filename=dol_sanitizeFileName($object->ref); + $filedir=$conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed=$user->rights->propal->creer; + $delallowed=$user->rights->propal->supprimer; + + $var=true; + + $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'',0,'',$soc->default_lang); + + + /* + * 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); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($object->ref,'/')); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // 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, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($object->ref,'/')); + $file=$fileparams['fullname']; + } + + 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=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false); + $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; + $formmail->substit['__SIGNATURE__']=$user->signature; + $formmail->substit['__PERSONALIZED__']=''; + // 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 (GETPOST("mode")=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); + } + + $formmail->show_form(); + + print '
'; } - - $formmail->show_form(); - - print '
'; } - // End of page llxFooter(); $db->close(); diff --git a/htdocs/comm/prospect/fiche.php b/htdocs/comm/prospect/fiche.php index bd08c74f647..dc447122561 100644 --- a/htdocs/comm/prospect/fiche.php +++ b/htdocs/comm/prospect/fiche.php @@ -296,7 +296,7 @@ if ($socid > 0) if (! empty($conf->propal->enabled) && $user->rights->propale->creer) { - print ''.$langs->trans("AddProp").''; + print ''.$langs->trans("AddProp").''; } // Add action diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index c837de7c9fb..5eb0c74a685 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -836,7 +836,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after) { $langs->load("propal"); $newmenu->add("/comm/propal/index.php?leftmenu=propals", $langs->trans("Prop"), 0, $user->rights->propale->lire, '', $mainmenu, 'propals'); - $newmenu->add("/societe/societe.php?leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer); + $newmenu->add("/comm/propal.php?action=create&leftmenu=propals", $langs->trans("NewPropal"), 1, $user->rights->propale->creer); $newmenu->add("/comm/propal/list.php?leftmenu=propals", $langs->trans("List"), 1, $user->rights->propale->lire); if ($leftmenu=="propals") $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=0", $langs->trans("PropalsDraft"), 2, $user->rights->propale->lire); if ($leftmenu=="propals") $newmenu->add("/comm/propal/list.php?leftmenu=propals&viewstatut=1", $langs->trans("PropalsOpened"), 2, $user->rights->propale->lire); diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 9e5f8da0e3b..12b4eb5f472 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -265,7 +265,7 @@ foreach ($listofreferent as $key => $value) { if ($key == 'propal' && ! empty($conf->propal->enabled) && $user->rights->propale->creer) { - print ''.$langs->trans("AddProp").''; + print ''.$langs->trans("AddProp").''; } if ($key == 'order' && ! empty($conf->commande->enabled) && $user->rights->commande->creer) {