diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 7d142611739..18bfc0d2bff 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2010 Juanjo Menent * * 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 @@ -21,20 +22,21 @@ /** * \file htdocs/fourn/commande/fiche.php - * \ingroup commande - * \brief Fiche commande + * \ingroup supplier, order + * \brief Card supplier order * \version $Id$ */ require("../../main.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); -require_once(DOL_DOCUMENT_ROOT."/html.formorder.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/html.formorder.class.php"); require_once(DOL_DOCUMENT_ROOT.'/includes/modules/supplier_order/modules_commandefournisseur.php'); -require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php"; -require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.product.class.php"; +require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.commande.class.php"; +require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php"; +require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php"; require_once DOL_DOCUMENT_ROOT."/lib/fourn.lib.php"; require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); -if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/project.class.php'); +if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'); $langs->load('orders'); $langs->load('sendings'); @@ -80,6 +82,30 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->com $id=$_REQUEST['id']; } +if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->commande->approuver) +{ + $order = new CommandeFournisseur($db); + $result = $order->fetch($_REQUEST['id']); + if ($order->statut == 5 || $order->statut == 6 || $order->statut == 7 || $order->statut == 9) + { + if ($order->statut == 5) $newstatus=4; // Received->Received partially + if ($order->statut == 6) $newstatus=2; // Canceled->Approved + if ($order->statut == 7) $newstatus=3; // Canceled->Process running + if ($order->statut == 9) $newstatus=1; // Refused->Validated + + $result = $order->setStatus($user,$newstatus); + if ($result > 0) + { + Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_REQUEST['id']); + exit; + } + else + { + $mesg='
'.$order->error.'
'; + } + } +} + /* * Ajout d'une ligne produit dans la commande */ @@ -125,7 +151,7 @@ if ($_POST['action'] == 'addline' && $user->rights->fournisseur->commande->creer $remise_percent = $_POST["remise_percent"] ? $_POST["remise_percent"] : $_POST["p_remise_percent"]; - $tva_tx = get_default_tva($societe,$mysoc,$product->tva_tx,$product->id); + $tva_tx = get_default_tva($societe,$mysoc,$product->id); $type = $product->type; $result=$commande->addline( @@ -206,6 +232,11 @@ if ($_POST['action'] == 'addline' && $user->rights->fournisseur->commande->creer */ if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->creer && $_POST['save'] == $langs->trans('Save')) { + $product=new Product($db); + if ($_POST["elrowid"]) + { + if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db); + } $commande = new CommandeFournisseur($db,"",$id); if ($commande->fetch($id) < 0) dol_print_error($db); @@ -217,7 +248,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->fournisseur->commande->c $_POST['tva_tx'], 'HT', 0, - $_POST["type"] + isset($_POST["type"])?$_POST["type"]:$product->type ); if ($result >= 0) @@ -324,11 +355,11 @@ if ($_REQUEST['action'] == 'confirm_commande' && $_REQUEST['confirm'] == 'yes' & } -if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->creer) +if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->fournisseur->commande->supprimer) { $commande = new CommandeFournisseur($db); - $commande->id = $id; - $result=$commande->delete(); + $commande->fetch($id); + $result=$commande->delete($user); if ($result > 0) { Header("Location: ".DOL_URL_ROOT.'/fourn/commande/liste.php'); @@ -340,6 +371,7 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && } } +// Receive if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) { $commande = new CommandeFournisseur($db); @@ -371,7 +403,7 @@ if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->rec } } -if ($_REQUEST["action"] == 'confirm_cancel' && $_REQUEST["confirm"] == 'yes' && $user->rights->fournisseur->commande->annuler) +if ($_REQUEST["action"] == 'confirm_cancel' && $_REQUEST["confirm"] == 'yes' && $user->rights->fournisseur->commande->commander) { $commande = new CommandeFournisseur($db); $commande->fetch($id); @@ -460,14 +492,14 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post } } -// Delete file +// Delete file in doc form if ($action=='remove_file') { $commande = new CommandeFournisseur($db); if ($commande->fetch($id)) { - $upload_dir = $conf->commande->dir_output . "/"; + $upload_dir = $conf->fournisseur->commande->dir_output . "/"; $file = $upload_dir . '/' . $_GET['file']; dol_delete_file($file); $mesg = '
'.$langs->trans("FileWasRemoved").'
'; @@ -509,6 +541,195 @@ if ($_GET["action"] == 'create') } } +/* + * 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 = $vardir.'/temp/'; + + $mesg=dol_add_file_process($upload_dir,0,0); + + $_GET["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 = $vardir.'/temp/'; + + $mesg=dol_remove_file_process($_POST['removedfile'],0); + + $_GET["action"]='presend'; + $_POST["action"]='presend'; +} + +/* + * Send mail + */ +if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) +{ + $langs->load('mails'); + + $commande= new CommandeFournisseur($db); + $result=$commande->fetch($_POST['orderid']); + $result=$commande->fetch_thirdparty(); + + if ($result > 0) + { + $ref = dol_sanitizeFileName($commande->ref); + $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.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']) + { + // Le destinataire a ete fourni via la liste deroulante + if ($_POST['receiver'] < 0) // Id du tiers + { + $sendto = $commande->client->email; + $sendtoid = 0; + } + else // Id du contact + { + $sendto = $commande->client->contact_get_email($_POST['receiver']); + $sendtoid = $_POST['receiver']; + } + } + + if (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 (strlen($_POST['subject'])) $subject=$_POST['subject']; + else $subject = $langs->transnoentities('CustomerOrder').' '.$commande->ref; + $actiontypecode='AC_SUP_ORD'; + $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']; + + // Send mail + 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',$from,$sendto).'.
'; + + $error=0; + + // Initialisation donnees + $commande->sendtoid=$sendtoid; + $commande->actiontypecode=$actiontypecode; + $commande->actionmsg = $actionmsg; + $commande->actionmsg2= $actionmsg2; + $commande->supplierorderrowid=$commande->id; + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$commande,$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='.$commande->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').' !
'; + $_GET["action"]='presend'; + 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("Invoice")).'
'; + dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.'); + } +} + /* * View @@ -519,6 +740,8 @@ llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur"); $html = new Form($db); $formfile = new FormFile($db); $formorder = new FormOrder($db); +$productstatic = new Product($db); + /* *************************************************************************** */ /* */ @@ -526,12 +749,11 @@ $formorder = new FormOrder($db); /* */ /* *************************************************************************** */ -$now=gmmktime(); - -$productstatic = new Product($db); +$now=dol_now(); $id = $_REQUEST['id']; $ref= $_REQUEST['ref']; + if ($id > 0 || ! empty($ref)) { //if ($mesg) print $mesg.'
'; @@ -545,8 +767,7 @@ if ($id > 0 || ! empty($ref)) $soc->fetch($commande->socid); $author = new User($db); - $author->id = $commande->user_author_id; - $author->fetch(); + $author->fetch($commande->user_author_id); $head = ordersupplier_prepare_head($commande); @@ -576,7 +797,7 @@ if ($id > 0 || ! empty($ref)) $text=$langs->trans('ConfirmValidateOrder',$newref); if ($conf->notification->enabled) { - require_once(DOL_DOCUMENT_ROOT ."/core/notify.class.php"); + require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php"); $notify=new Notify($db); $text.='
'; $text.=$notify->confirmMessage(3,$commande->socid); @@ -595,7 +816,6 @@ if ($id > 0 || ! empty($ref)) } /* * Confirmation de la desapprobation - * */ if ($_GET['action'] == 'refuse') { @@ -636,6 +856,14 @@ if ($id > 0 || ! empty($ref)) */ $nbrow=8; if ($conf->projet->enabled) $nbrow++; + + //Local taxes + if ($mysoc->pays_code=='ES') + { + if($mysoc->localtax1_assuj=="1") $nbrow++; + if($mysoc->localtax2_assuj=="1") $nbrow++; + } + print ''; // Ref @@ -678,12 +906,12 @@ if ($id > 0 || ! empty($ref)) } } - // Auteur + // Author print ''; print ''; print ''; - // Projet + // Project if ($conf->projet->enabled) { $langs->load('projects'); @@ -691,9 +919,10 @@ if ($id > 0 || ! empty($ref)) print '
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).'
'; - if ($_GET['action'] != 'classer' && $commande->brouillon) print ''; + if ($_GET['action'] != 'classer') print ''; print '
'; print $langs->trans('Project'); print ''.img_edit($langs->trans('SetProject')).''.img_edit($langs->trans('SetProject')).'
'; print ''; + //print "$commande->id, $commande->socid, $commande->fk_project"; if ($_GET['action'] == 'classer') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->fk_project, 'projectid'); @@ -714,6 +943,22 @@ if ($id > 0 || ! empty($ref)) print ''.$langs->trans("AmountVAT").''.price($commande->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($propal->total_localtax1).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + } + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + { + print ''.$langs->transcountry("AmountLT2",$mysoc->pays_code).''; + print ''.price($propal->total_localtax2).''; + print ''.$langs->trans("Currency".$conf->monnaie).''; + } + } print ''.$langs->trans("AmountTTC").''.price($commande->total_ttc).''; print ''.$langs->trans("Currency".$conf->monnaie).''; @@ -830,27 +1075,38 @@ if ($id > 0 || ! empty($ref)) // Ligne en mode update if ($_GET["action"] == 'editline' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $commandline->id)) { + print "\n"; print '
id.'" method="post">'; print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; print ''; // ancre pour retourner sur la ligne - if (($conf->produit->enabled || $conf->service->enabled) && $commandline->fk_product > 0) + if (($conf->product->enabled || $conf->service->enabled) && $commandline->fk_product > 0) { - print ''; + $product_static=new ProductFournisseur($db); + $product_static->fetch($commandline->fk_product); + $text=$product_static->getNomUrl(1); + $text.= ' - '.$product_static->libelle; + $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($commandline->description)); + print $html->textwithtooltip($text,$description,3,'','',$i); + + // Show range + print_date_range($commandline->date_start,$commandline->date_end); + /* + print ''; print img_object($langs->trans('ShowProduct'),'product'); print ' '.$commandline->ref_fourn.''; print ' ('.$commandline->ref.')'; print ' - '.nl2br($commandline->product); - print '
'; + print '
';*/ } else { print $html->select_type_of_lines($commandline->product_type,'type',1); - if ($conf->produit->enabled && $conf->service->enabled) print '
'; + if ($conf->product->enabled && $conf->service->enabled) print '
'; } // Description - Editor wysiwyg @@ -873,7 +1129,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print '%'; - print ''; + print ''; print '
'; print '' . "\n"; print "
\n"; @@ -909,8 +1165,8 @@ if ($id > 0 || ! empty($ref)) $forceall=1; print $html->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,0,$forceall); - if ($forceall || ($conf->produit->enabled && $conf->service->enabled) - || (empty($conf->produit->enabled) && empty($conf->service->enabled))) print '
'; + if ($forceall || ($conf->product->enabled && $conf->service->enabled) + || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; // Editor wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) @@ -941,7 +1197,7 @@ if ($id > 0 || ! empty($ref)) print ''; // Ajout de produits/services predefinis - if ($conf->produit->enabled || $conf->service->enabled) + if ($conf->product->enabled || $conf->service->enabled) { print ''; print ''; @@ -999,133 +1255,220 @@ if ($id > 0 || ! empty($ref)) print ''; - /** - * Boutons actions - */ - if ($user->societe_id == 0 && $_GET['action'] != 'editline' && $_GET['action'] != 'delete') + if ($_GET['action'] != 'presend') { - print '
'; - if ($commande->statut == 0 && $num > 0) + /** + * Boutons actions + */ + if ($user->societe_id == 0 && $_GET['action'] != 'editline' && $_GET['action'] != 'delete') { - if ($user->rights->fournisseur->commande->valider) - { - print ''.$langs->trans('Validate').''; - } - } + print '
'; - if ($commande->statut == 1) - { - if ($user->rights->fournisseur->commande->approuver) + // Validate + if ($commande->statut == 0 && $num > 0) { - print ''.$langs->trans("ApproveOrder").''; - - print ''.$langs->trans("RefuseOrder").''; + if ($user->rights->fournisseur->commande->valider) + { + print ''.$langs->trans('Validate').''; + } } - if ($user->rights->fournisseur->commande->annuler) + // Approve + if ($commande->statut == 1) { - print ''.$langs->trans("CancelOrder").''; + if ($user->rights->fournisseur->commande->approuver) + { + print ''.$langs->trans("ApproveOrder").''; + + print ''.$langs->trans("RefuseOrder").''; + } } - } - - if ($commande->statut == 2) - { - if ($user->rights->fournisseur->commande->annuler) + // Send + if ($commande->statut == 2) { - print ''.$langs->trans("CancelOrder").''; + if ($user->rights->fournisseur->commande->commander) + { + $comref = dol_sanitizeFileName($commande->ref); + $file = $conf->fournisseur->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; + if (file_exists($file)) + { + print ''.$langs->trans('SendByMail').''; + } + } } + + // Cancel + if ($commande->statut == 2) + { + if ($user->rights->fournisseur->commande->commander) + { + print ''.$langs->trans("CancelOrder").''; + } + } + + // Reopen + if ($commande->statut == 5 || $commande->statut == 6 || $commande->statut == 7 || $commande->statut == 9) + { + if ($user->rights->fournisseur->commande->commander) + { + print ''.$langs->trans("ReOpen").''; + } + } + + // Delete + if ($user->rights->fournisseur->commande->supprimer) + { + print ''.$langs->trans("Delete").''; + } + + print "
"; } - if ($user->rights->fournisseur->commande->annuler) + + print '
'; + print ''; // ancre + + /* + * Documents generes + */ + $comfournref = dol_sanitizeFileName($commande->ref); + $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf'; + $relativepath = $comfournref.'/'.$comfournref.'.pdf'; + $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref; + $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; + $genallowed=$user->rights->fournisseur->commande->creer; + $delallowed=$user->rights->fournisseur->commande->supprimer; + + $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); + + print ''; + + if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) { - print ''.$langs->trans("Delete").''; + /** + * Commander (action=commande) + */ + print '
'; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + print '
'.$langs->trans("ToOrder").'
'.$langs->trans("OrderDate").''; + $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); + print $html->select_date($date_com,'','','','',"commande"); + print '
'.$langs->trans("OrderMode").''; + $formorder->select_methodes_commande($_POST["methodecommande"],"methodecommande",1); + print '
'.$langs->trans("Comment").'
'; + print '
'; } - print ""; + if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) + { + /** + * Receptionner (action=livraison) + */ + print '
'; + print '
'; + print ''; + print ''; + print ''; + print ''; + print '\n"; + + print "'; + print ''; + print ''; + print "
'.$langs->trans("Receive").'
'.$langs->trans("DeliveryDate").''; + print $html->select_date('','','','','',"commande"); + print "
".$langs->trans("Delivery")."\n"; + $liv = array(); + $liv[''] = ' '; + $liv['tot'] = $langs->trans("TotalWoman"); + $liv['par'] = $langs->trans("PartialWoman"); + $liv['nev'] = $langs->trans("NeverReceived"); + $liv['can'] = $langs->trans("Canceled"); + + print $html->select_array("type",$liv); + + print '
'.$langs->trans("Comment").'
\n"; + print "
\n"; + } + + // List of actions on element + // include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); + // $formactions=new FormActions($db); + // $somethingshown=$formactions->showactions($commande,'supplier_order',$socid); + + + print '
'; } - print '
'; - print ''; // ancre /* - * Documents generes + * Action presend + * */ - $comfournref = dol_sanitizeFileName($commande->ref); - $file = $conf->fournisseur->dir_output . '/commande/' . $comfournref . '/' . $comfournref . '.pdf'; - $relativepath = $comfournref.'/'.$comfournref.'.pdf'; - $filedir = $conf->fournisseur->dir_output . '/commande/' . $comfournref; - $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; - $genallowed=$user->rights->fournisseur->commande->creer; - $delallowed=$user->rights->fournisseur->commande->supprimer; - - $somethingshown=$formfile->show_documents('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); - - - print ''; - - - if ( $user->rights->fournisseur->commande->commander && ($commande->statut == 2 || $commande->statut == 6)) + if ($_GET['action'] == 'presend') { - /** - * Commander (action=commande) - */ + $ref = dol_sanitizeFileName($commande->ref); + $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; + print '
'; - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + print_titre($langs->trans('SendOrderByMail')); - print ''; + // Cree l'objet formulaire mail + 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('SendOrderRef','__ORDERREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__ORDERREF__']=$commande->ref; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='supplier_order_send'; + $formmail->param['orderid']=$commande->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$commande->id; - print ''; - print ''; - print '
'.$langs->trans("ToOrder").'
'.$langs->trans("OrderDate").''; - $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); - print $html->select_date($date_com,'','','','',"commande"); - print '
'.$langs->trans("OrderMode").''; - $formorder->select_methodes_commande($_POST["methodecommande"],"methodecommande",1); - print '
'.$langs->trans("Comment").'
'; - print '
'; + // Init list of files + if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,$ref.'.pdf','application/pdf'); + } + + // Show form + $formmail->show_form(); + + print '
'; } - if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) - { - /** - * Receptionner (action=livraison) - */ - print '
'; - print '
'; - print ''; - print ''; - print ''; - print ''; - print '\n"; - - print "'; - print ''; - print ''; - print "
'.$langs->trans("Receive").'
'.$langs->trans("DeliveryDate").''; - print $html->select_date('','','','','',"commande"); - print "
".$langs->trans("Delivery")."\n"; - $liv = array(); - $liv[''] = ' '; - $liv['tot'] = $langs->trans("TotalWoman"); - $liv['par'] = $langs->trans("PartialWoman"); - $liv['nev'] = $langs->trans("NeverReceived"); - $liv['can'] = $langs->trans("Canceled"); - - print $html->select_array("type",$liv); - - print '
'.$langs->trans("Comment").'
\n"; - print "
\n"; - } print '
'; + } else {