* Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2008 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** \file htdocs/commande/fiche.php \ingroup commande \brief Fiche commande client \version $Id$ */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php'); require_once(DOL_DOCUMENT_ROOT."/lib/order.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/lib/project.lib.php'); if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT.'/propal.class.php'); $langs->load('orders'); $langs->load('sendings'); $langs->load('companies'); $langs->load('bills'); $langs->load('propal'); $langs->load('deliveries'); $langs->load('products'); if (!$user->rights->commande->lire) accessforbidden(); // Securite acces client $socid=0; if ($user->societe_id > 0) { $socid = $user->societe_id; } if ($user->societe_id >0 && isset($_GET["id"]) && $_GET["id"]>0) { $commande = new Commande($db); $commande->fetch((int)$_GET['id']); if ($user->societe_id != $commande->socid) { accessforbidden(); } } // Recuperation de l'id de projet $projetid = 0; if ($_GET["projetid"]) { $projetid = $_GET["projetid"]; } /******************************************************************************/ /* Actions */ /******************************************************************************/ // Suppression de la commande if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') { if ($user->rights->commande->supprimer ) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->delete($user); Header('Location: index.php'); exit; } } /* * Supprime une ligne produit AVEC ou SANS confirmation */ if (($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) || ($_GET['action'] == 'deleteline' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)) { if ($user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result = $commande->delete_line($_GET['lineid']); if ($result > 0) { if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $_GET['id'], $commande->modelpdf, $outputlangs); } else { print $commande->error; } } Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']); exit; } // Categorisation dans projet if ($_POST['action'] == 'classin') { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->setProject($_POST['projetid']); } // Ajout commande if ($_POST['action'] == 'add' && $user->rights->commande->creer) { $datecommande=''; $datecommande = dolibarr_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $datelivraison = dolibarr_mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']); $commande = new Commande($db); $commande->socid=$_POST['socid']; $commande->fetch_client(); $db->begin(); $commande->date_commande = $datecommande; $commande->note = $_POST['note']; $commande->note_public = $_POST['note_public']; $commande->source = $_POST['source_id']; $commande->projetid = $_POST['projetid']; $commande->ref_client = $_POST['ref_client']; $commande->modelpdf = $_POST['model']; $commande->cond_reglement_id = $_POST['cond_reglement_id']; $commande->mode_reglement_id = $_POST['mode_reglement_id']; $commande->date_livraison = $datelivraison; $commande->adresse_livraison_id = $_POST['adresse_livraison_id']; $commande->contactid = $_POST['contactidp']; $NBLINES=8; for ($i = 1 ; $i <= $NBLINES ; $i++) { if ($_POST['idprod'.$i]) { $xid = 'idprod'.$i; $xqty = 'qty'.$i; $xremise = 'remise_percent'.$i; $commande->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]); } } $commande_id = $commande->create($user); if ($commande_id > 0) { // Insertion contact par defaut si defini if ($_POST["contactidp"]) { $result=$commande->add_contact($_POST["contactidp"],'CUSTOMER','external'); if ($result > 0) { $error=0; } else { $mesg = '
'.$langs->trans("ErrorFailedToAddContact").'
'; $error=1; } } $_GET['id'] = $commande->id; $action = ''; } // Fin creation facture, on l'affiche if ($commande_id > 0 && ! $error) { $db->commit(); } else { $db->rollback(); $_GET["action"]='create'; $_GET['socid']=$_POST['socid']; if (! $mesg) $mesg='
'.$commande->error.'
'; } } // Positionne ref commande client if ($_POST['action'] == 'set_ref_client' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_ref_client($user, $_POST['ref_client']); } if ($_POST['action'] == 'setremise' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_remise($user, $_POST['remise']); } if ($_POST['action'] == "setabsolutediscount" && $user->rights->commande->creer) { if ($_POST["remise_id"]) { $com = new Commande($db); $com->id=$_GET['id']; $ret=$com->fetch($_GET['id']); if ($ret > 0) { $com->insert_discount($_POST["remise_id"]); } else { dolibarr_print_error($db,$com->error); } } } if ($_POST['action'] == 'setdate_livraison' && $user->rights->commande->creer) { //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datelivraison=dolibarr_mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->set_date_livraison($user,$datelivraison); if ($result < 0) { $mesg='
'.$commande->error.'
'; } } if ($_POST['action'] == 'setdeliveryadress' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_adresse_livraison($user,$_POST['adresse_livraison_id']); } if ($_POST['action'] == 'setmode' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->mode_reglement($_POST['mode_reglement_id']); if ($result < 0) dolibarr_print_error($db,$commande->error); } if ($_POST['action'] == 'setconditions' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->cond_reglement($_POST['cond_reglement_id']); if ($result < 0) dolibarr_print_error($db,$commande->error); } if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->facture->creer) { $commande = new Commande($db); $commande->fetch($_REQUEST['id']); $result = $commande->set_remise($user, $_POST['remise_percent']); $_GET['id']=$_REQUEST['id']; } if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer) { $commande = new Commande($db); $commande->fetch($_REQUEST['id']); $result = $commande->set_remise_absolue($user, $_POST['remise_absolue']); $_GET['id']=$_REQUEST['id']; } /* * Ajout d'une ligne produit dans la commande */ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { if ($_POST['qty'] && (($_POST['pu'] != '' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'])) { $commande = new Commande($db); $ret=$commande->fetch($_POST['id']); if ($ret < 0) { dolibarr_print_error($db,$commande->error); exit; } $ret=$commande->fetch_client(); $price_base_type = 'HT'; // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit if ($_POST['idprod']) { $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$commande->client,$prod->tva_tx); // multiprix if ($conf->global->PRODUIT_MULTIPRICES == 1) { $pu_ht = $prod->multiprices[$commande->client->price_level]; $pu_ttc = $prod->multiprices_ttc[$commande->client->price_level]; $price_base_type = $prod->multiprices_base_type[$commande->client->price_level]; } else { $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; $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'] ? "\n" : ""; $desc.= $_POST['np_desc']; } else { $pu_ht=$_POST['pu']; $tva_tx=eregi_replace('\*','',$_POST['tva_tx']); $tva_npr=eregi('\*',$_POST['tva_tx'])?1:0; $desc=$_POST['dp_desc']; } $info_bits=0; if ($tva_npr) $info_bits |= 0x01; // Insert line $result = $commande->addline( $_POST['id'], $desc, $pu_ht, $_POST['qty'], $tva_tx, $_POST['idprod'], $_POST['remise_percent'], $info_bits, '', $price_base_type, $pu_ttc ); if ($result > 0) { if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); } else { $mesg='
'.$commande->error.'
'; } } } /* * Mise a jour d'une ligne dans la commande */ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save')) { $commande = new Commande($db,'',$_POST['id']); if (! $commande->fetch($_POST['id']) > 0) dolibarr_print_error($db); // Define info_bits $info_bits=0; if (eregi('\*',$_POST['tva_tx'])) $info_bits |= 0x01; // Define vat_rate $vat_rate=$_POST['tva_tx']; $vat_rate=eregi_replace('\*','',$vat_rate); $result = $commande->updateline($_POST['elrowid'], $_POST['eldesc'], $_POST['pu'], $_POST['qty'], $_POST['elremise_percent'], $vat_rate, 'HT', $info_bits ); if ($result >= 0) { if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); } else { dolibarr_print_error($db,$commande->error); exit; } $_GET['id']=$_POST['id']; // Pour reaffichage de la fiche en cours d'edition } if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['cancel'] == $langs->trans('Cancel')) { Header('Location: fiche.php?id='.$_POST['id']); // Pour reaffichage de la fiche en cours d'edition exit; } if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result=$commande->valid($user); if ($result >= 0) { if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); } } if ($_REQUEST['action'] == 'confirm_close' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result = $commande->cloture($user); } if ($_REQUEST['action'] == 'confirm_cancel' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider) { $commande = new Commande($db); $commande->fetch($_GET['id']); $result = $commande->cancel($user); } if ($_GET['action'] == 'modif' && $user->rights->commande->creer) { /* * Repasse la commande en mode brouillon */ $commande = new Commande($db); $commande->fetch($_GET['id']); $commande->set_draft($user); } /* * Ordonnancement des lignes */ if ($_GET['action'] == 'up' && $user->rights->commande->creer) { $commande = new Commande($db,'',$_GET['id']); $commande->fetch($_GET['id']); $commande->line_up($_GET['rowid']); if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']); exit; } if ($_GET['action'] == 'down' && $user->rights->commande->creer) { $commande = new Commande($db,'',$_GET['id']); $commande->fetch($_GET['id']); $commande->line_down($_GET['rowid']); if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']); exit; } if ($_REQUEST['action'] == 'builddoc') // In get or post { /* * Generate order document * define into /includes/modules/commande/modules_commande.php */ // Sauvegarde le dernier modele choisi pour generer un document $commande = new Commande($db, 0, $_REQUEST['id']); $commande->fetch($_REQUEST['id']); if ($_REQUEST['model']) { $commande->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } $result=commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); if ($result <= 0) { dolibarr_print_error($db,$result); exit; } else { Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc'); exit; } } // Efface les fichiers if ($_REQUEST['action'] == 'remove_file') { $com = new Commande($db); if ($com->fetch($id)) { $upload_dir = $conf->commande->dir_output . "/"; $file = $upload_dir . '/' . urldecode($_GET['file']); dol_delete_file($file); $mesg = '
'.$langs->trans("FileWasRemoved").'
'; } } /* * Envoi de la commande par mail */ if ($_POST['action'] == 'send') { $langs->load('mails'); $commande= new Commande($db); if ( $commande->fetch($_POST['orderid']) ) { $orderref = sanitize_string($commande->ref); $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf'; if (is_readable($file)) { $commande->fetch_client(); 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('Order').' '.$commande->ref; $actiontypecode='AC_COM'; $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); } $filepath[0] = $file; $filename[0] = $commande->ref.'.pdf'; $mimetype[0] = 'application/pdf'; if ($_FILES['addedfile']['tmp_name']) { $filepath[1] = $_FILES['addedfile']['tmp_name']; $filename[1] = $_FILES['addedfile']['name']; $mimetype[1] = $_FILES['addedfile']['type']; } // Envoi de la commande 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->orderrowid=$commande->id; // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $interface=new Interfaces($db); $result=$interface->run_triggers('ORDER_SENTBYMAIL',$commande,$user,$langs,$conf); if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers if ($error) { dolibarr_print_error($db); } else { // Renvoie sur la fiche Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&msg='.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').' !
'; dolibarr_syslog('Recipient email is empty'); } } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; dolibarr_syslog('Failed to read file: '.$file); } } else { $langs->load("other"); $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
'; dolibarr_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.'); } } /* * View */ llxHeader('',$langs->trans('Order'),'Commande'); $html = new Form($db); $formfile = new FormFile($db); /********************************************************************* * * Mode creation * *********************************************************************/ if ($_GET['action'] == 'create' && $user->rights->commande->creer) { print_titre($langs->trans('CreateOrder')); if ($mesg) print $mesg.'
'; $new_commande = new Commande($db); if ($propalid) { $sql = 'SELECT s.nom, s.prefix_comm, s.rowid'; $sql.= ', p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, p.fk_cond_reglement, p.fk_mode_reglement'; $sql.= ', '.$db->pdate('p.datep').' as dp'; $sql.= ', c.id as statut, c.label as lst'; $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c'; $sql .= ' WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id'; $sql .= ' AND p.rowid = '.$propalid; } else { $sql = 'SELECT s.nom, s.prefix_comm, s.rowid, s.mode_reglement, s.cond_reglement '; $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s '; $sql .= 'WHERE s.rowid = '.$_GET['socid']; } $resql = $db->query($sql); if ( $resql ) { $num = $db->num_rows($resql); if ($num) { $obj = $db->fetch_object($resql); $soc = new Societe($db); $soc->fetch($obj->rowid); $nbrow=10; print '
'; print ''; print '' ."\n"; print ''; print ''; print ''; // Reference print ''; // Reference client print ''; print ''; // Client print ''; /* * Contact de la commande */ print "'; // Ligne info remises tiers print ''; // Date print ''; // Date de livraison print ""; // Adresse de livraison print ''; // Conditions de reglement print ''; // Mode de reglement print ''; // Projet if ($conf->projet->enabled) { $projetid=$_POST["projetid"]?$_POST["projetid"]:$commande->projetid; print ''; } print ''; print ''; print '"; // Note publique print ''; print ''; print ''; // Note privée if (! $user->societe_id) { print ''; print ''; print ''; } if ($propalid > 0) { $amount = ($obj->price); print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print ''; print ''; print ''; print ''; } else { if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) { /* * Services/produits predefinis */ $NBLINES=8; print ''; } } /* * */ print ''; print '
'.$langs->trans('Ref').''.$langs->trans("Draft").'
'.$langs->trans('RefCustomer').''; print '
'.$langs->trans('Customer').''.$soc->getNomUrl(1).'
".$langs->trans("DefaultContact").''; $html->select_contacts($soc->id,$setcontact,'contactidp',1); 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->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print '
'.$langs->trans('Date').''; $html->select_date('','re','','','',"crea_commande"); print '
".$langs->trans("DeliveryDate").""; if ($conf->global->DATE_LIVRAISON_WEEK_DELAY) { $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); $html->select_date($tmpdte,'liv_','','',1,"crea_commande"); } else { $html->select_date(-1,'liv_','','',1,"crea_commande"); } print "
'.$langs->trans('DeliveryAddress').''; $numaddress = $html->select_adresse_livraison($soc->adresse_livraison_id, $_GET['socid'],'adresse_livraison_id',1); if ($numaddress==0) { print '   '.$langs->trans("AddAddress").''; } print '
'.$langs->trans('PaymentConditionsShort').''; $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1); print '
'.$langs->trans('PaymentMode').''; $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id'); print '
'.$langs->trans('Project').''; $numprojet=select_projects($soc->id,$projetid,'projetid'); if ($numprojet==0) { print '   '.$langs->trans("AddProject").''; } print '
'.$langs->trans('Source').''; $html->selectSourcesCommande('','source_id',1); print '
'.$langs->trans('Model').''; // pdf include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php'); $model=new ModelePDFCommandes(); $liste=$model->liste_modeles($db); $html->select_array('model',$liste,$conf->global->COMMANDE_ADDON_PDF); print "
'.$langs->trans('NotePublic').''; print '
'.$langs->trans('NotePrivate').''; print '
'.$langs->trans('Ref').''.$obj->ref.'
'.$langs->trans('TotalTTC').''.price($amount).'
'.$langs->trans('VAT').''.price($obj->tva).'
'.$langs->trans('TotalTTC').''.price($obj->total).'
'; print ''; print ''; print ''; print ''; print ''; for ($i = 1 ; $i <= $NBLINES ; $i++) { print ''; print ''; print ''; } print '
'.$langs->trans('ProductsAndServices').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').'
'; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); else print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); print '%
'; print '
'; print '
'; if ($propalid) { /* * Produits */ print_titre($langs->trans('Products')); print ''; print ''; print ''; print ''; print ''; print ''; $var=false; $sql = 'SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent'; $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt, '.MAIN_DB_PREFIX.'product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = '.$propalid; $sql .= ' ORDER BY pt.rowid ASC'; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ''; print ''; print ''; print ''; print ''; $i++; } } $sql = 'SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent'; $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt WHERE pt.fk_propal = '.$propalid.' AND pt.fk_product = 0'; $sql .= ' ORDER BY pt.rowid ASC'; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object(); $var=!$var; print ''; print ''; print ''; print ''; print ''; $i++; } } else { dolibarr_print_error($db); } print '
'.$langs->trans('Ref').''.$langs->trans('Product').''.$langs->trans('Price').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').'
['.$objp->ref.']'.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.''.price($objp->price).''.$objp->qty.'
'.$objp->remise_percent.'%
 '.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.''.price($objp->price).''.$objp->qty.'
'.$objp->remise_percent.'%
'; } } } else { dolibarr_print_error($db); } } else { /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ $id = $_GET['id']; if ($id > 0) { if ($mesg) print $mesg.'
'; $commande = new Commande($db); if ( $commande->fetch($_GET['id']) > 0) { $soc = new Societe($db); $soc->fetch($commande->socid); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); $head = commande_prepare_head($commande); dolibarr_fiche_head($head, 'order', $langs->trans("CustomerOrder")); /* * Confirmation de la suppression de la commande */ if ($_GET['action'] == 'delete') { $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete'); print '
'; } /* * Confirmation de la validation */ if ($_GET['action'] == 'validate') { // on verifie si la facture est en numerotation provisoire $ref = substr($commande->ref, 1, 4); if ($ref == 'PROV') { $num = $commande->getNextNumRef($soc); } else { $num = $commande->ref; } $text=$langs->trans('ConfirmValidateOrder',$num); $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_validate'); print '
'; } /* * Confirmation de la cloture */ if ($_GET['action'] == 'close') { $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close'); print '
'; } /* * Confirmation de l'annulation */ if ($_GET['action'] == 'cancel') { $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel'); print '
'; } /* * Confirmation de la suppression d'une ligne produit */ if ($_GET['action'] == 'ask_deleteline' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) { $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline'); print '
'; } /* * Commande */ $nbrow=8; if ($conf->projet->enabled) $nbrow++; print ''; // Ref print ''; print ''; print ''; // Ref commande client print ''; print ''; // Societe print ''; print ''; print ''; // Ligne info remises tiers print ''; // Date print ''; print ''; print ''; print ''; // Date de livraison if ($conf->expedition->enabled) { print ''; print ''; print ''; // Adresse de livraison print ''; } // Conditions et modes de reglement print ''; //Note public lorsque le module expedition n'est pas active if (!$conf->projet->enabled) $nbrow--; if (!$conf->expedition->enabled) { $nbrow--; if ($conf->projet->enabled) $nbrow--; print ''; } print ''; print ''; // Projet if ($conf->projet->enabled) { $langs->load('projects'); print ''; } // Lignes de 3 colonnes // Total HT print ''; print ''; print ''; // Total TVA print ''; print ''; // Total TTC print ''; print ''; // Statut print ''; print ''; print ''; print '
'.$langs->trans('Ref').''.$commande->ref.'
'; print ''; if ($_GET['action'] != 'RefCustomerOrder' && $commande->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Modify')).'
'; print '
'; if ($user->rights->commande->creer && $_GET['action'] == 'RefCustomerOrder') { print '
'; print ''; print ''; print ' '; print '
'; } else { print $commande->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"); $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); print '. '; if ($absolute_discount) { if ($commande->statut > 0) { print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->transnoentities("Currency".$conf->monnaie)); } else { // Remise dispo de type non avoir $filter='fk_facture_source IS NULL'; print '
'; print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->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 '
'.$langs->trans('Date').''.dolibarr_print_date($commande->date,'daytext').''.$langs->trans('Source').' : '.$commande->getLabelSource(); if ($commande->source == 0 && $conf->propal->enabled) { // Si source = propal $propal = new Propal($db); $propal->fetch($commande->propale_id); print ' -> '.$propal->ref.''; } print '
'; print ''; if ($_GET['action'] != 'editdate_livraison' && $commande->brouillon) print ''; print '
'; print $langs->trans('DeliveryDate'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'
'; print '
'; if ($_GET['action'] == 'editdate_livraison') { print '
'; print ''; $html->select_date($commande->date_livraison,'liv_','','','',"setdate_livraison"); print ''; print '
'; } else { print $commande->date_livraison ? dolibarr_print_date($commande->date_livraison,'daytext') : ' '; } print '
'.$langs->trans('NotePublic').' :
'; print nl2br($commande->note_public); print '
'; print ''; if ($_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print ''; print '
'; print $langs->trans('DeliveryAddress'); print 'socid.'&id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; print '
'; if ($_GET['action'] == 'editdelivery_adress') { $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id); } else { $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id); } print '
'; print ''; if ($_GET['action'] != 'editconditions' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($_GET['action'] == 'editconditions') { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'cond_reglement_id'); } else { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->cond_reglement_id,'none'); } print ''.$langs->trans('NotePublic').' :
'; print nl2br($commande->note_public); print '
'; print ''; if ($_GET['action'] != 'editmode' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($_GET['action'] == 'editmode') { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->mode_reglement_id,'none'); } print '
'; print ''; if ($_GET['action'] != 'classer' && $commande->brouillon) print ''; print '
'; print $langs->trans('Project'); print ''.img_edit($langs->trans('SetProject')).'
'; print '
'; if ($_GET['action'] == 'classer') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'projetid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->socid, $commande->projet_id, 'none'); } print '
'.$langs->trans('AmountHT').''.price($commande->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($commande->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($commande->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('Status').''.$commande->getLibStatut(4).'

'; print "\n"; /* * Lignes de commandes */ $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, '; $sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; $sql.= ' WHERE l.fk_commande = '.$commande->id; $sql.= ' ORDER BY l.rang ASC, l.rowid'; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; print ''; if ($num) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; // Ligne en mode visu if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { print ''; } else { print ''; } print ''; print ''; print ''; if ($objp->remise_percent > 0) { print ''; } else { print ''; } print ''; // Icone d'edition et suppression if ($commande->statut == 0 && $user->rights->commande->creer) { print ''; print ''; if ($num > 1) { print ''; } } else { print ''; } print ''; } // Ligne en mode update if ($_GET['action'] == 'editline' && $user->rights->commande->creer && $_GET['rowid'] == $objp->rowid) { print 'rowid.'" method="post">'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } $total = $total + ($objp->qty * $objp->price); $i++; } $db->free($resql); $numlines=$num; } else { dolibarr_print_error($db); } /* * Ajouter une ligne */ if ($commande->statut == 0 && $user->rights->commande->creer && $_GET["action"] <> 'editline') { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Ajout produit produits/services personnalises print ''; print ''; print ''; $var=true; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Ajout de produits/services predefinis if ($conf->produit->enabled) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } } print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').' 
'; print ''; // ancre pour retourner sur la ligne // Affiche ligne produit $text = ''; if ($objp->fk_product_type==1) $text.= img_object($langs->trans('ShowService'),'service'); else $text.= img_object($langs->trans('ShowProduct'),'product'); $text.= ' '.$objp->ref.''; $text.= ' - '.$objp->product; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); // Todo: voir si on insert ou pas en option les dates de debut et de fin de service //print_date_range($objp->date_start,$objp->date_end); if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product)?'
'.dol_htmlentitiesbr($objp->description):''; } print '
'; print ''; // ancre pour retourner sur la ligne if (($objp->info_bits & 2) == 2) { print ''; print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); print ''; if ($objp->description) { if ($objp->description == '(CREDIT_NOTE)') { require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); $discount=new DiscountAbsolute($db); $discount->fetch($objp->fk_remise_except); print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); } else { print ' - '.nl2br($objp->description); } } } else { print nl2br($objp->description); } print ''.vatrate($objp->tva_tx,'%',$objp->info_bits).''.price($objp->subprice).''; if (($objp->info_bits & 2) != 2) { print $objp->qty; } else print ' '; print ''.dolibarr_print_reduction($objp->remise_percent).' '.price($objp->total_ht).''; if (($objp->info_bits & 2) == 2) { // Ligne remise predefinie, on ne permet pas modif } else { print 'rowid.'#'.$objp->rowid.'">'; print img_edit(); print ''; } print ''; if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) { if ($conf->use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { $url = $_SERVER["PHP_SELF"].'?id='.$id.'&lineid='.$objp->rowid.'&action=confirm_deleteline&confirm=yes'; print 'trans("No").'\',\'deleteline'.$i.'\')">'; } else { print 'rowid.'">'; } } else { print 'rowid.'">'; } print img_delete(); print ''; if ($i > 0) { print 'rowid.'">'; print img_up(); print ''; } if ($i < $num-1) { print 'rowid.'">'; print img_down(); print ''; } print ' 
'; print ''; // ancre pour retourner sur la ligne if ($objp->fk_product > 0) { print ''; if ($objp->fk_product_type==1) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; print ' - '.nl2br($objp->product); print '
'; } // editeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('eldesc',$objp->description,200,'dolibarr_details'); $doleditor->Create(); } else { print ''; } print '
'; if($soc->tva_assuj == "0") print '0'; else print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$soc); print ''; if (($objp->info_bits & 2) != 2) { print ''; } else print ' '; print ''; if (($objp->info_bits & 2) != 2) { print '%'; } else print ' '; print ''; print '
'; print ''; // ancre print $langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; // editeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('dp_desc','',100,'dolibarr_details'); $doleditor->Create(); } else { print ''; } print ''; if($soc->tva_assuj == "0") print '0'; else print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); print '%
'; if ($conf->service->enabled) { print $langs->trans('RecordedProductsAndServices'); } else { print $langs->trans('RecordedProducts'); } print ''.$langs->trans('Qty').''.$langs->trans('ReductionShort').' 
'; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) { $html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level); } else { $html->select_produits('','idprod','',$conf->produit->limit_size); } if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; // editeur wysiwyg if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_DETAILS) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('np_desc','',100,'dolibarr_details'); $doleditor->Create(); } else { print ''; } print '
%
'; print ''; /* * Boutons actions */ if ($user->societe_id == 0 && $_GET['action'] <> 'editline') { print '
'; // Valid if ($commande->statut == 0 && $commande->total_ttc >= 0 && $numlines > 0 && $user->rights->commande->valider) { print 'use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { // on verifie si la commande est en numerotation provisoire $ref = substr($commande->ref, 1, 4); if ($ref == 'PROV') { $num = $commande->getNextNumRef($soc); } else { $num = $commande->ref; } $url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_validate&confirm=yes'; print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmValidateOrder',$num).'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'validate\')"'; } else { print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=validate"'; } print '>'.$langs->trans('Validate').''; } // Edit if ($commande->statut == 1) { if ($user->rights->commande->creer) { print ''.$langs->trans('Modify').''; } } // Send if ($commande->statut > 0) { if ($user->rights->commande->envoyer) { $comref = sanitize_string($commande->ref); $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; if (file_exists($file)) { print ''.$langs->trans('SendByMail').''; } } } // Ship if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer && $commande->getNbOfProductsLines() > 0) { // Chargement des permissions $error = $user->load_entrepots(); if (sizeof($user->entrepots) === 1) { print ''; print $langs->trans('ShipProduct').''; } else { print ''.$langs->trans('ShipProduct').''; } } // Cloturer if ($commande->statut == 1 || $commande->statut == 2) { if ($user->rights->commande->cloturer) { print 'use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { $url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_close&confirm=yes'; print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmCloseOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'close\')"'; } else { print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=close"'; } print '>'.$langs->trans('Close').''; } } // Annuler commande if ($commande->statut == 1) { $nb_expedition = $commande->nb_expedition(); if ($user->rights->commande->annuler && $nb_expedition == 0) { print 'use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { $url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_cancel&confirm=yes'; print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmCancelOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'cancel\')"'; } else { print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=cancel"'; } print '>'.$langs->trans('CancelOrder').''; } } // Supprimer commande if ($commande->statut == 0 && $user->rights->commande->supprimer) { print 'use_javascript_ajax && $conf->global->MAIN_CONFIRM_AJAX) { $url = $_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=confirm_delete&confirm=yes'; print 'href="#" onClick="dialogConfirm(\''.$url.'\',\''.$langs->trans('ConfirmDeleteOrder').'\',\''.$langs->trans("Yes").'\',\''.$langs->trans("No").'\',\'delete\')"'; } else { print 'href="'.$_SERVER["PHP_SELF"].'?id='.$commande->id.'&action=delete"'; } print '>'.$langs->trans('Delete').''; } print '
'; } print '
'; print '
'; print ''; // ancre /* * Documents generes * */ $comref = sanitize_string($commande->ref); $file = $conf->commande->dir_output . '/' . $comref . '/' . $comref . '.pdf'; $relativepath = $comref.'/'.$comref.'.pdf'; $filedir = $conf->commande->dir_output . '/' . $comref; $urlsource=$_SERVER["PHP_SELF"]."?id=".$commande->id; $genallowed=$user->rights->commande->creer; $delallowed=$user->rights->commande->supprimer; $somethingshown=$formfile->show_documents('commande',$comref,$filedir,$urlsource,$genallowed,$delallowed,$commande->modelpdf); /* * Liste des factures */ $sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'co_fa as cf'; $sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); if ($num) { print '
'; print_titre($langs->trans('RelatedBills')); $i = 0; $total = 0; print ''; print '"; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ''; print ''; print ''; print ''; $i++; } print '
'.$langs->trans('Ref')."'.$langs->trans('Date').''.$langs->trans('Price').'
'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.''.dolibarr_print_date($objp->df,'day').''.$objp->total_ttc.'
'; } } else { dolibarr_print_error($db); } print '
'; // List of actions on element include_once(DOL_DOCUMENT_ROOT.'/html.formactions.class.php'); $formactions=new FormActions($db); $somethingshown=$formactions->showactions($commande,'order',$socid); print '
'; /* * Action presend * */ if ($_GET['action'] == 'presend') { $orderref = sanitize_string($commande->ref); $file = $conf->commande->dir_output . '/' . $orderref . '/' . $orderref . '.pdf'; // Construit PDF si non existant if (! is_readable($file)) { if ($_REQUEST['lang_id']) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($_REQUEST['lang_id']); } $result=commande_pdf_create($db, $_REQUEST['id'], '', $_REQUEST['model'], $outputlangs); if ($result <= 0) { dolibarr_print_error($db,$result); exit; } } print '
'; print_titre($langs->trans('SendOrderByMail')); $soc = new Societe($db); $soc->fetch($commande->socid); $liste[0]=" "; foreach ($soc->thirdparty_and_contact_email_array() as $key=>$value) { $liste[$key]=$value; } // Cree l'objet formulaire mail include_once('../html.formmail.class.php'); $formmail = new FormMail($db); $formmail->fromtype = 'user'; $formmail->fromid = $user->id; $formmail->fromname = $user->fullname; $formmail->frommail = $user->email; $formmail->withfrom=1; $formmail->withto=$liste; $formmail->withtocc=1; $formmail->withtopic=$langs->trans('SendOrderRef','__ORDERREF__'); $formmail->withfile=1; $formmail->withbody=1; $formmail->withdeliveryreceipt=1; // Tableau des substitutions $formmail->substit['__ORDERREF__']=$commande->ref; // Tableau des parametres complementaires $formmail->param['action']='send'; $formmail->param['models']='order_send'; $formmail->param['orderid']=$commande->id; $formmail->param['returnurl']=DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id; $formmail->show_form(); print '
'; } } else { // Commande non trouvee dolibarr_print_error($db); } } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>