2004-11-29 17:48:53 +01:00
< ? php
2006-12-11 17:03:34 +01:00
/* Copyright ( C ) 2004 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2013-04-16 01:13:20 +02:00
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2008-07-01 21:57:52 +02:00
* Copyright ( C ) 2005 Eric Seigne < eric . seigne @ ryxeo . com >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2013-03-12 15:06:38 +01:00
* Copyright ( C ) 2010 - 2013 Juanjo Menent < jmenent @ 2 byte . es >
2011-05-04 23:20:51 +02:00
* Copyright ( C ) 2011 Philippe Grand < philippe . grand @ atoo - net . com >
2012-08-15 15:52:51 +02:00
* Copyright ( C ) 2012 Marcos García < marcosgdf @ gmail . com >
2013-04-09 17:18:07 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2004-11-29 17:48:53 +01:00
*
2006-12-05 01:47:40 +01:00
* 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 .
2004-11-29 17:48:53 +01:00
*
2006-12-05 01:47:40 +01:00
* This program is distributed in the hope that it will be useful ,
2011-05-04 23:20:51 +02:00
* 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 .
*
2011-12-17 21:58:44 +01:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
* or see http :// www . gnu . org /
2011-05-04 23:20:51 +02:00
*/
/**
* \file htdocs / fourn / commande / fiche . php
* \ingroup supplier , order
* \brief Card supplier order
*/
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
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 . '/core/modules/supplier_order/modules_commandefournisseur.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 . '/core/lib/fourn.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2013-01-23 11:28:11 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2013-04-09 17:18:07 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2013-01-23 11:28:11 +01:00
if ( ! empty ( $conf -> produit -> enabled ))
2012-08-25 03:28:30 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
2013-01-23 11:28:11 +01:00
if ( ! empty ( $conf -> projet -> enabled ))
2012-08-25 03:28:30 +02:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2011-05-04 23:20:51 +02:00
$langs -> load ( 'orders' );
$langs -> load ( 'sendings' );
$langs -> load ( 'companies' );
$langs -> load ( 'bills' );
$langs -> load ( 'propal' );
$langs -> load ( 'deliveries' );
$langs -> load ( 'products' );
$langs -> load ( 'stocks' );
2012-02-27 22:26:22 +01:00
$id = GETPOST ( 'id' , 'int' );
2012-04-10 17:21:28 +02:00
$ref = GETPOST ( 'ref' , 'alpha' );
$action = GETPOST ( 'action' , 'alpha' );
$confirm = GETPOST ( 'confirm' , 'alpha' );
$comclientid = GETPOST ( 'comid' , 'int' );
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2012-04-10 17:21:28 +02:00
$projectid = GETPOST ( 'projectid' , 'int' );
2012-05-21 17:12:57 +02:00
2012-07-02 19:30:37 +02:00
//PDF
2012-05-21 18:44:09 +02:00
$hidedetails = ( GETPOST ( 'hidedetails' , 'int' ) ? GETPOST ( 'hidedetails' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS ) ? 1 : 0 ));
$hidedesc = ( GETPOST ( 'hidedesc' , 'int' ) ? GETPOST ( 'hidedesc' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_DESC ) ? 1 : 0 ));
$hideref = ( GETPOST ( 'hideref' , 'int' ) ? GETPOST ( 'hideref' , 'int' ) : ( ! empty ( $conf -> global -> MAIN_GENERATE_DOCUMENTS_HIDE_REF ) ? 1 : 0 ));
2012-05-21 17:12:57 +02:00
2011-05-04 23:20:51 +02:00
// Security check
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2013-03-24 21:06:45 +01:00
$result = restrictedArea ( $user , 'fournisseur' , $id , '' , 'commande' );
2011-05-04 23:20:51 +02:00
2012-02-29 14:32:22 +01:00
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
2012-03-02 14:51:16 +01:00
$hookmanager -> initHooks ( array ( 'ordersuppliercard' ));
2012-02-29 14:32:22 +01:00
2011-05-09 11:44:06 +02:00
$object = new CommandeFournisseur ( $db );
2013-12-16 11:13:39 +01:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
2011-05-09 11:44:06 +02:00
2012-12-01 15:45:05 +01:00
// Load object
if ( $id > 0 || ! empty ( $ref ))
{
$ret = $object -> fetch ( $id , $ref );
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
$ret = $object -> fetch_thirdparty ();
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
}
2013-03-12 15:06:38 +01:00
else if ( ! empty ( $socid ) && $socid > 0 )
2012-12-01 15:45:05 +01:00
{
$fourn = new Fournisseur ( $db );
$ret = $fourn -> fetch ( $socid );
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
$object -> socid = $fourn -> id ;
$ret = $object -> fetch_thirdparty ();
if ( $ret < 0 ) dol_print_error ( $db , $object -> error );
}
2011-05-04 23:20:51 +02:00
/*
* Actions
*/
2012-04-13 14:02:53 +02:00
if ( $action == 'setref_supplier' && $user -> rights -> fournisseur -> commande -> creer )
{
$result = $object -> setValueFrom ( 'ref_supplier' , GETPOST ( 'ref_supplier' , 'alpha' ));
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
2011-05-04 23:20:51 +02:00
2011-10-14 16:44:22 +02:00
// conditions de reglement
2011-05-04 23:20:51 +02:00
if ( $action == 'setconditions' && $user -> rights -> fournisseur -> commande -> creer )
{
2012-03-13 19:24:11 +01:00
$result = $object -> setPaymentTerms ( GETPOST ( 'cond_reglement_id' , 'int' ));
2011-05-04 23:20:51 +02:00
}
2011-05-05 23:35:07 +02:00
// mode de reglement
2012-03-18 11:13:01 +01:00
else if ( $action == 'setmode' && $user -> rights -> fournisseur -> commande -> creer )
2011-05-05 23:35:07 +02:00
{
2012-03-13 20:01:10 +01:00
$result = $object -> setPaymentMethods ( GETPOST ( 'mode_reglement_id' , 'int' ));
2011-05-05 23:35:07 +02:00
}
2012-04-10 17:21:28 +02:00
// date de livraison
if ( $action == 'setdate_livraison' && $user -> rights -> fournisseur -> commande -> creer )
{
$datelivraison = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'liv_month' , 'int' ), GETPOST ( 'liv_day' , 'int' ), GETPOST ( 'liv_year' , 'int' ));
$result = $object -> set_date_livraison ( $user , $datelivraison );
if ( $result < 0 )
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2012-04-10 17:21:28 +02:00
}
}
2008-02-24 16:51:06 +01:00
// Set project
2012-03-18 11:13:01 +01:00
else if ( $action == 'classin' && $user -> rights -> fournisseur -> commande -> creer )
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
$object -> setProject ( $projectid );
2004-11-29 17:48:53 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'setremisepercent' && $user -> rights -> fournisseur -> commande -> creer )
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
$result = $object -> set_remise ( $user , $_POST [ 'remise_percent' ]);
2006-12-05 01:47:40 +01:00
}
2005-08-31 23:56:05 +02:00
2012-04-13 14:02:53 +02:00
else if ( $action == 'setnote_public' && $user -> rights -> fournisseur -> commande -> creer )
2012-04-10 17:21:28 +02:00
{
2013-04-10 10:58:38 +02:00
$result = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_public' ), ENT_QUOTES ), '_public' );
2012-04-10 17:21:28 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
}
2013-04-09 17:18:07 +02:00
else if ( $action == 'setnote_private' && $user -> rights -> fournisseur -> commande -> creer )
2012-04-10 17:21:28 +02:00
{
2013-04-10 10:58:38 +02:00
$result = $object -> update_note ( dol_html_entity_decode ( GETPOST ( 'note_private' ), ENT_QUOTES ), '_private' );
2012-04-10 17:21:28 +02:00
if ( $result < 0 ) dol_print_error ( $db , $object -> error );
2012-03-18 11:13:01 +01:00
}
else if ( $action == 'reopen' && $user -> rights -> fournisseur -> commande -> approuver )
2010-05-28 23:52:51 +02:00
{
2012-11-03 19:15:45 +01:00
if ( in_array ( $object -> statut , array ( 1 , 5 , 6 , 7 , 9 )))
2011-10-14 16:44:22 +02:00
{
2012-11-03 19:15:45 +01:00
if ( $object -> statut == 1 ) $newstatus = 0 ; // Validated->Draft
else if ( $object -> statut == 5 ) $newstatus = 4 ; // Received->Received partially
else if ( $object -> statut == 6 ) $newstatus = 2 ; // Canceled->Approved
else if ( $object -> statut == 7 ) $newstatus = 3 ; // Canceled->Process running
else if ( $object -> statut == 9 ) $newstatus = 1 ; // Refused->Validated
2011-10-14 16:44:22 +02:00
2012-11-03 19:15:45 +01:00
$result = $object -> setStatus ( $user , $newstatus );
2011-10-14 16:44:22 +02:00
if ( $result > 0 )
{
2012-11-03 19:15:45 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
else
{
2012-11-03 19:15:45 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
}
2010-05-28 23:52:51 +02:00
}
2004-11-29 17:48:53 +01:00
/*
2010-12-01 22:16:28 +01:00
* Add a line into product
2004-11-29 17:48:53 +01:00
*/
2012-03-18 11:13:01 +01:00
else if ( $action == 'addline' && $user -> rights -> fournisseur -> commande -> creer )
2004-11-29 17:48:53 +01:00
{
2012-08-15 15:52:51 +02:00
$langs -> load ( 'errors' );
2012-12-01 15:45:05 +01:00
$error = 0 ;
2012-08-15 15:52:51 +02:00
2013-11-17 23:25:25 +01:00
// Set if we used free entry or predefined product
2014-02-28 16:00:57 +01:00
if ( GETPOST ( 'addline_libre' )
|| ( GETPOST ( 'dp_desc' ) && ! GETPOST ( 'addline_libre' ) && ! GETPOST ( 'idprod' , 'int' ) > 0 ) // we push enter onto qty field
)
2013-11-17 23:25:25 +01:00
{
$predef = '' ;
$idprod = 0 ;
$product_desc = ( GETPOST ( 'dp_desc' ) ? GETPOST ( 'dp_desc' ) : '' );
$price_ht = GETPOST ( 'price_ht' );
$tva_tx = ( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) : 0 );
}
2014-02-28 16:00:57 +01:00
if ( GETPOST ( 'addline_predefined' )
|| ( ! GETPOST ( 'dp_desc' ) && ! GETPOST ( 'addline_predefined' ) && GETPOST ( 'idprod' , 'int' ) > 0 ) // we push enter onto qty field
)
2013-11-17 23:25:25 +01:00
{
$predef = (( $conf -> global -> MAIN_FEATURES_LEVEL < 2 ) ? '_predef' : '' );
$idprod = GETPOST ( 'idprod' , 'int' );
$product_desc = ( GETPOST ( 'product_desc' ) ? GETPOST ( 'product_desc' ) : ( GETPOST ( 'np_desc' ) ? GETPOST ( 'np_desc' ) : '' ));
$price_ht = '' ;
$tva_tx = '' ;
}
$qty = GETPOST ( 'qty' . $predef );
$remise_percent = GETPOST ( 'remise_percent' . $predef );
if ( GETPOST ( 'addline_libre' ) && GETPOST ( 'pu' ) < 0 && $qty < 0 )
2012-08-15 15:52:51 +02:00
{
2012-08-16 13:10:14 +02:00
setEventMessage ( $langs -> trans ( 'ErrorBothFieldCantBeNegative' , $langs -> transnoentitiesnoconv ( 'UnitPrice' ), $langs -> transnoentitiesnoconv ( 'Qty' )), 'errors' );
2012-12-01 15:45:05 +01:00
$error ++ ;
2012-08-15 15:52:51 +02:00
}
2013-11-17 23:25:25 +01:00
if ( GETPOST ( 'addline_libre' ) && ! GETPOST ( 'idprodfournprice' ) && GETPOST ( 'type' ) < 0 )
2012-08-15 15:52:51 +02:00
{
2012-08-16 13:10:14 +02:00
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Type' )), 'errors' );
2012-12-01 15:45:05 +01:00
$error ++ ;
2012-08-15 15:52:51 +02:00
}
2014-03-17 15:38:12 +01:00
if ( ! GETPOST ( 'addline_predefined' ) && ( GETPOST ( 'pu' ) === '' )) // Unit price can be 0 but not ''
2012-08-15 15:52:51 +02:00
{
2014-03-17 15:38:12 +01:00
2012-08-16 13:10:14 +02:00
setEventMessage ( $langs -> trans ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'UnitPrice' ))), 'errors' );
2012-12-01 15:45:05 +01:00
$error ++ ;
2012-08-15 15:52:51 +02:00
}
2013-11-17 23:25:25 +01:00
if ( ! GETPOST ( 'addline_predefined' ) && ! GETPOST ( 'np_desc' ) && ! GETPOST ( 'dp_desc' ))
2012-08-15 15:52:51 +02:00
{
2012-08-16 13:10:14 +02:00
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Description' )), 'errors' );
2012-12-01 15:45:05 +01:00
$error ++ ;
2012-08-15 15:52:51 +02:00
}
2013-11-17 23:25:25 +01:00
if (( ! GETPOST ( 'addline_predefined' ) && ( ! GETPOST ( 'qty' ) || GETPOST ( 'qty' ) == '' ))
|| ( GETPOST ( 'addline_predefined' ) && ( ! GETPOST ( 'qty_predef' ) || GETPOST ( 'qty_predef' ) == '' )))
2012-08-15 15:52:51 +02:00
{
2012-08-16 13:10:14 +02:00
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( 'Qty' )), 'errors' );
2012-12-01 15:45:05 +01:00
$error ++ ;
2012-08-15 15:52:51 +02:00
}
2013-11-17 23:25:25 +01:00
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
2014-03-26 11:28:41 +01:00
if ( GETPOST ( 'addline_predefined' ) || GETPOST ( 'idprodfournprice' )) // With combolist idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
2011-10-14 16:44:22 +02:00
{
2013-11-17 23:25:25 +01:00
$idprod = 0 ;
$productsupplier = new ProductFournisseur ( $db );
if ( GETPOST ( 'idprodfournprice' ) == '' )
{
$idprod =- 1 ;
}
if ( GETPOST ( 'idprodfournprice' ) > 0 )
{
$idprod = $productsupplier -> get_buyprice ( GETPOST ( 'idprodfournprice' ), $qty ); // Just to see if a price exists for the quantity. Not used to found vat
}
if ( $idprod > 0 )
{
$res = $productsupplier -> fetch ( $idprod );
$label = $productsupplier -> libelle ;
$desc = $productsupplier -> description ;
if ( trim ( $product_desc ) != trim ( $desc )) $desc = dol_concatdesc ( $desc , $product_desc );
$tva_tx = get_default_tva ( $object -> thirdparty , $mysoc , $productsupplier -> id , GETPOST ( 'idprodfournprice' ));
$type = $productsupplier -> type ;
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $mysoc , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $mysoc , $object -> thirdparty );
$result = $object -> addline (
$desc ,
$productsupplier -> fourn_pu ,
$qty ,
$tva_tx ,
$localtax1_tx ,
$localtax2_tx ,
$productsupplier -> id ,
GETPOST ( 'idprodfournprice' ),
$productsupplier -> fourn_ref ,
$remise_percent ,
'HT' ,
$type
);
}
if ( $idprod == 0 )
{
// Product not selected
$error ++ ;
$langs -> load ( " errors " );
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " ProductOrService " )), 'errors' );
}
if ( $idprod == - 1 )
{
// Quantity too low
$error ++ ;
$langs -> load ( " errors " );
setEventMessage ( $langs -> trans ( " ErrorQtyTooLowForThisSupplier " ), 'errors' );
}
}
2014-03-17 15:38:12 +01:00
else if ( GETPOST ( 'pu' ) !== '' || GETPOST ( 'amountttc' ) !== '' )
2013-11-17 23:25:25 +01:00
{
$type = $_POST [ " type " ];
$desc = $_POST [ 'dp_desc' ];
$tva_tx = price2num ( $_POST [ 'tva_tx' ]);
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $mysoc , $object -> thirdparty );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $mysoc , $object -> thirdparty );
if ( ! $product_desc )
{
setEventMessage ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Label " )), 'errors' );
}
else
{
if ( ! empty ( $_POST [ 'pu' ]))
{
$price_base_type = 'HT' ;
$ht = price2num ( $_POST [ 'pu' ]);
$result = $object -> addline ( $desc , $ht , $qty , $tva_tx , $localtax1_tx , $localtax2_tx , 0 , 0 , '' , $remise_percent , $price_base_type , 0 , $type );
}
else
{
$ttc = price2num ( $_POST [ 'amountttc' ]);
$ht = $ttc / ( 1 + ( $tauxtva / 100 ));
$price_base_type = 'HT' ;
2014-03-17 15:38:12 +01:00
$result = $object -> addline ( $desc , $ht , $qty , $tva_tx , $localtax1_tx , $localtax2_tx , 0 , 0 , '' , $remise_percent , $price_base_type , $ttc , $type );
2013-11-17 23:25:25 +01:00
}
}
}
2013-03-02 16:17:12 +01:00
2013-11-17 23:25:25 +01:00
//print "xx".$tva_tx; exit;
if ( ! $error && $result > 0 )
{
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
// Define output language
$outputlangs = $langs ;
$newlang = GETPOST ( 'lang_id' , 'alpha' );
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) $newlang = $object -> client -> default_lang ;
if ( ! empty ( $newlang ))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
}
supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
}
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'remise_percent' ]);
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'pu' ]);
unset ( $_POST [ 'tva_tx' ]);
unset ( $_POST [ 'label' ]);
unset ( $localtax1_tx );
unset ( $localtax2_tx );
unset ( $_POST [ 'idprodfournprice' ]);
unset ( $_POST [ 'qty_predef' ]);
unset ( $_POST [ 'remise_percent_predef' ]);
unset ( $_POST [ 'fournprice_predef' ]);
unset ( $_POST [ 'buying_price_predef' ]);
unset ( $_POST [ 'np_desc' ]);
}
else
{
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2004-11-29 17:48:53 +01:00
}
2006-12-05 01:47:40 +01:00
/*
2008-01-07 11:26:31 +01:00
* Mise a jour d ' une ligne dans la commande
2006-12-05 01:47:40 +01:00
*/
2013-12-08 16:39:47 +01:00
else if ( $action == 'update_line' && $user -> rights -> fournisseur -> commande -> creer && ! GETPOST ( 'cancel' ))
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
if ( $_POST [ " elrowid " ])
{
2013-06-05 18:19:50 +02:00
$line = new CommandeFournisseurLigne ( $db );
2013-06-16 21:31:21 +02:00
$res = $line -> fetch ( $_POST [ " elrowid " ]);
2013-06-05 18:19:50 +02:00
if ( ! $res ) dol_print_error ( $db );
2011-10-14 16:44:22 +02:00
}
2013-01-05 09:43:40 +01:00
$localtax1_tx = get_localtax ( $_POST [ 'tva_tx' ], 1 , $mysoc , $object -> thirdparty );
$localtax2_tx = get_localtax ( $_POST [ 'tva_tx' ], 2 , $mysoc , $object -> thirdparty );
2011-10-14 16:44:22 +02:00
$result = $object -> updateline (
2011-11-09 22:10:58 +01:00
$_POST [ 'elrowid' ],
$_POST [ 'eldesc' ],
$_POST [ 'pu' ],
$_POST [ 'qty' ],
$_POST [ 'remise_percent' ],
$_POST [ 'tva_tx' ],
$localtax1_tx ,
$localtax2_tx ,
'HT' ,
0 ,
2013-06-05 18:19:50 +02:00
isset ( $_POST [ " type " ]) ? $_POST [ " type " ] : $line -> product_type
2011-10-14 16:44:22 +02:00
);
2013-06-05 18:19:50 +02:00
unset ( $_POST [ 'qty' ]);
unset ( $_POST [ 'type' ]);
unset ( $_POST [ 'idprodfournprice' ]);
unset ( $_POST [ 'remmise_percent' ]);
unset ( $_POST [ 'dp_desc' ]);
unset ( $_POST [ 'np_desc' ]);
unset ( $_POST [ 'pu' ]);
unset ( $_POST [ 'tva_tx' ]);
unset ( $localtax1_tx );
unset ( $localtax2_tx );
2011-10-14 16:44:22 +02:00
if ( $result >= 0 )
{
$outputlangs = $langs ;
2012-12-01 15:45:05 +01:00
if ( GETPOST ( 'lang_id' ))
2011-10-14 16:44:22 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2012-12-01 15:45:05 +01:00
$outputlangs -> setDefaultLang ( GETPOST ( 'lang_id' ));
2011-10-14 16:44:22 +02:00
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
2012-12-01 15:45:05 +01:00
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
2013-01-26 10:35:30 +01:00
supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2011-12-02 19:57:20 +01:00
}
2011-10-14 16:44:22 +02:00
}
else
{
dol_print_error ( $db , $object -> error );
exit ;
}
2006-12-05 01:47:40 +01:00
}
2006-10-05 11:39:39 +02:00
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_deleteproductline' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> creer )
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
2011-11-09 22:10:58 +01:00
$result = $object -> deleteline ( GETPOST ( 'lineid' ));
if ( $result >= 0 )
{
2011-10-14 16:44:22 +02:00
$outputlangs = $langs ;
2012-12-01 15:45:05 +01:00
if ( GETPOST ( 'lang_id' ))
2011-10-14 16:44:22 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2012-12-01 15:45:05 +01:00
$outputlangs -> setDefaultLang ( GETPOST ( 'lang_id' ));
2011-10-14 16:44:22 +02:00
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
2012-12-01 15:45:05 +01:00
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
2013-01-26 10:35:30 +01:00
supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2011-12-02 19:57:20 +01:00
}
2011-10-14 16:44:22 +02:00
}
2011-11-09 22:10:58 +01:00
else
{
$error ++ ;
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-11-09 22:10:58 +01:00
}
if ( ! $error )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-11-09 22:10:58 +01:00
exit ;
}
2004-11-29 17:48:53 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_valid' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> valider )
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
$object -> date_commande = dol_now ();
$result = $object -> valid ( $user );
if ( $result >= 0 )
{
$outputlangs = $langs ;
2012-12-01 15:45:05 +01:00
if ( GETPOST ( 'lang_id' ))
2011-10-14 16:44:22 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2012-12-01 15:45:05 +01:00
$outputlangs -> setDefaultLang ( GETPOST ( 'lang_id' ));
2011-10-14 16:44:22 +02:00
}
2011-12-02 19:57:20 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE ))
{
2012-12-01 15:45:05 +01:00
$ret = $object -> fetch ( $object -> id ); // Reload to get new records
2013-01-26 10:35:30 +01:00
supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2011-12-02 19:57:20 +01:00
}
2011-10-14 16:44:22 +02:00
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2011-11-09 22:10:58 +01:00
// If we have permission, and if we don't need to provide th idwarehouse, we go directly on approved step
if ( $user -> rights -> fournisseur -> commande -> approuver && ! ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER ) && $object -> hasProductsOrServices ( 1 )))
2011-10-14 16:44:22 +02:00
{
$action = 'confirm_approve' ;
}
2004-11-29 17:48:53 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_approve' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> approuver )
2004-11-29 17:48:53 +01:00
{
2012-04-13 14:02:53 +02:00
$idwarehouse = GETPOST ( 'idwarehouse' , 'int' );
2011-11-09 22:10:58 +01:00
// Check parameters
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER ) && $object -> hasProductsOrServices ( 1 ))
2011-10-14 16:44:22 +02:00
{
2011-11-09 22:10:58 +01:00
if ( ! $idwarehouse || $idwarehouse == - 1 )
{
$error ++ ;
2012-12-01 15:45:05 +01:00
setEventMessage ( $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentitiesnoconv ( " Warehouse " )), 'errors' );
2011-11-09 22:10:58 +01:00
$action = '' ;
}
2011-10-14 16:44:22 +02:00
}
2011-11-09 22:10:58 +01:00
if ( ! $error )
2011-10-14 16:44:22 +02:00
{
2011-11-09 22:10:58 +01:00
$result = $object -> approve ( $user , $idwarehouse );
if ( $result > 0 )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-11-09 22:10:58 +01:00
exit ;
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-11-09 22:10:58 +01:00
}
2011-10-14 16:44:22 +02:00
}
2004-11-29 17:48:53 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_refuse' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> approuver )
2004-11-29 17:48:53 +01:00
{
2011-10-14 16:44:22 +02:00
$result = $object -> refuse ( $user );
if ( $result > 0 )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2004-11-30 20:09:33 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_commande' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> commander )
2004-11-30 20:09:33 +01:00
{
2011-10-14 16:44:22 +02:00
$result = $object -> commande ( $user , $_REQUEST [ " datecommande " ], $_REQUEST [ " methode " ], $_REQUEST [ 'comment' ]);
if ( $result > 0 )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2004-11-30 20:09:33 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> supprimer )
2004-11-30 20:09:33 +01:00
{
2011-10-14 16:44:22 +02:00
$result = $object -> delete ( $user );
if ( $result > 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . DOL_URL_ROOT . '/fourn/commande/liste.php' );
2011-10-14 16:44:22 +02:00
exit ;
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2004-11-29 17:48:53 +01:00
}
2012-12-01 15:45:05 +01:00
// Action clone object
else if ( $action == 'confirm_clone' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> creer )
{
if ( 1 == 0 && ! GETPOST ( 'clone_content' ) && ! GETPOST ( 'clone_receivers' ))
{
setEventMessage ( $langs -> trans ( " NoCloneOptionsSpecified " ), 'errors' );
}
else
{
if ( $object -> id > 0 )
{
2013-01-26 10:35:30 +01:00
$result = $object -> createFromClone ();
2012-12-01 15:45:05 +01:00
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . '?id=' . $result );
exit ;
}
else
{
setEventMessage ( $object -> error , 'errors' );
$action = '' ;
}
}
}
}
2010-05-28 23:52:51 +02:00
// Receive
2012-03-18 11:13:01 +01:00
else if ( $action == 'livraison' && $user -> rights -> fournisseur -> commande -> receptionner )
2005-04-05 11:58:15 +02:00
{
2011-10-14 16:44:22 +02:00
if ( $_POST [ " type " ])
{
$date_liv = dol_mktime ( 0 , 0 , 0 , $_POST [ " remonth " ], $_POST [ " reday " ], $_POST [ " reyear " ]);
$result = $object -> Livraison ( $user , $date_liv , $_POST [ " type " ], $_POST [ " comment " ]);
if ( $result > 0 )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
else if ( $result == - 3 )
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $langs -> trans ( " NotAuthorized " ), 'errors' );
2011-10-14 16:44:22 +02:00
}
else
{
dol_print_error ( $db , $object -> error );
exit ;
}
}
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Delivery " )) . '</div>' ;
}
2005-04-05 11:58:15 +02:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'confirm_cancel' && $confirm == 'yes' && $user -> rights -> fournisseur -> commande -> commander )
2005-04-08 17:06:20 +02:00
{
2011-10-14 16:44:22 +02:00
$result = $object -> cancel ( $user );
if ( $result > 0 )
{
2012-12-01 15:45:05 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
2005-04-08 17:06:20 +02:00
}
2011-02-23 15:44:29 +01:00
// Line ordering
2012-03-18 11:13:01 +01:00
else if ( $action == 'up' && $user -> rights -> fournisseur -> commande -> creer )
2006-02-17 17:29:58 +01:00
{
2011-10-14 16:44:22 +02:00
$object -> line_up ( $_GET [ 'rowid' ]);
$outputlangs = $langs ;
if ( ! empty ( $_REQUEST [ 'lang_id' ]))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2013-01-26 10:35:30 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2012-12-01 15:45:05 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#' . $_GET [ 'rowid' ]));
2011-10-14 16:44:22 +02:00
exit ;
2006-02-17 17:29:58 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'down' && $user -> rights -> fournisseur -> commande -> creer )
2006-02-17 17:29:58 +01:00
{
2011-10-14 16:44:22 +02:00
$object -> line_down ( $_GET [ 'rowid' ]);
$outputlangs = $langs ;
if ( ! empty ( $_REQUEST [ 'lang_id' ]))
{
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $_REQUEST [ 'lang_id' ]);
}
2013-01-26 10:35:30 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_PDF_AUTOUPDATE )) supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2012-08-31 05:58:38 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $id . ( empty ( $conf -> global -> MAIN_JUMP_TAG ) ? '' : '#' . $_GET [ 'rowid' ]));
2011-10-14 16:44:22 +02:00
exit ;
2006-02-17 17:29:58 +01:00
}
2012-03-18 11:13:01 +01:00
else if ( $action == 'builddoc' && $user -> rights -> fournisseur -> commande -> creer ) // En get ou en post
2006-12-05 01:47:40 +01:00
{
2011-10-14 16:44:22 +02:00
// Build document
2013-09-06 13:25:45 +02:00
// Save last template used to generate document
if ( GETPOST ( 'model' )) $object -> setDocModel ( $user , GETPOST ( 'model' , 'alpha' ));
2013-11-17 23:25:25 +01:00
2011-10-14 16:44:22 +02:00
$outputlangs = $langs ;
2012-12-01 15:45:05 +01:00
if ( GETPOST ( 'lang_id' ))
2011-10-14 16:44:22 +02:00
{
$outputlangs = new Translate ( " " , $conf );
2012-12-01 15:45:05 +01:00
$outputlangs -> setDefaultLang ( GETPOST ( 'lang_id' ));
2011-10-14 16:44:22 +02:00
}
2013-01-26 10:35:30 +01:00
$result = supplier_order_pdf_create ( $db , $object , $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2011-10-14 16:44:22 +02:00
if ( $result <= 0 )
{
dol_print_error ( $db , $result );
exit ;
}
2006-12-05 01:47:40 +01:00
}
2005-08-31 23:56:05 +02:00
2010-05-12 13:29:21 +02:00
// Delete file in doc form
2012-12-01 15:45:05 +01:00
else if ( $action == 'remove_file' && $object -> id > 0 && $user -> rights -> fournisseur -> commande -> creer )
2006-12-05 01:47:40 +01:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2012-12-01 15:45:05 +01:00
$langs -> load ( " other " );
$upload_dir = $conf -> fournisseur -> commande -> dir_output ;
$file = $upload_dir . '/' . GETPOST ( 'file' );
$ret = dol_delete_file ( $file , 0 , 0 , 0 , $object );
if ( $ret ) setEventMessage ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )));
else setEventMessage ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), 'errors' );
2006-12-05 01:47:40 +01:00
}
2006-03-16 02:25:19 +01:00
2013-12-16 11:13:39 +01:00
elseif ( $action == 'update_extras' )
{
// Fill array 'array_options' with data from add form
$extralabels = $extrafields -> fetch_name_optionals_label ( $object -> table_element );
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
if ( $ret < 0 )
$error ++ ;
if ( ! $error ) {
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager -> initHooks ( array ( 'supplierorderdao' ));
$parameters = array ( 'id' => $object -> id );
$reshook = $hookmanager -> executeHooks ( 'insertExtraFields' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( empty ( $reshook ))
{
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
{
$result = $object -> insertExtraFields ();
if ( $result < 0 )
{
$error ++ ;
}
}
}
else if ( $reshook < 0 ) $error ++ ;
}
else
{
$action = 'edit_extras' ;
}
}
2006-12-05 01:47:40 +01:00
/*
2009-03-23 18:11:25 +01:00
* Create an order
2006-12-05 01:47:40 +01:00
*/
2013-03-12 15:06:38 +01:00
else if ( $action == 'add' && $user -> rights -> fournisseur -> commande -> creer )
2004-11-29 17:48:53 +01:00
{
2013-03-12 15:06:38 +01:00
$error = 0 ;
2012-01-19 09:53:27 +01:00
2013-03-12 15:06:38 +01:00
if ( $socid < 1 )
2011-10-14 16:44:22 +02:00
{
2013-03-12 15:06:38 +01:00
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorFieldRequired' , $langs -> transnoentities ( 'Supplier' )) . '</div>' ;
$action = 'create' ;
$error ++ ;
2012-01-19 09:53:27 +01:00
}
2006-12-05 01:47:40 +01:00
2012-01-19 09:53:27 +01:00
if ( ! $error )
{
2013-03-12 15:06:38 +01:00
$db -> begin ();
2008-04-19 19:26:41 +02:00
2013-03-12 15:06:38 +01:00
// Creation commande
$object -> ref_supplier = GETPOST ( 'refsupplier' );
$object -> socid = $socid ;
2013-07-30 16:21:39 +02:00
$object -> cond_reglement_id = GETPOST ( 'cond_reglement_id' );
$object -> mode_reglement_id = GETPOST ( 'mode_reglement_id' );
2013-04-09 17:18:07 +02:00
$object -> note_private = GETPOST ( 'note_private' );
2013-03-12 15:06:38 +01:00
$object -> note_public = GETPOST ( 'note_public' );
2013-12-16 11:13:39 +01:00
// Fill array 'array_options' with data from add form
$ret = $extrafields -> setOptionalsFromPost ( $extralabels , $object );
2013-03-12 15:06:38 +01:00
$id = $object -> create ( $user );
if ( $id < 0 )
{
$error ++ ;
}
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
if ( $error )
{
$langs -> load ( " errors " );
$db -> rollback ();
$mesg = '<div class="error">' . $langs -> trans ( $object -> error ) . '</div>' ;
$action = 'create' ;
$_GET [ 'socid' ] = $_POST [ 'socid' ];
}
else
{
$db -> commit ();
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $id );
exit ;
}
2011-10-14 16:44:22 +02:00
}
2006-12-05 01:47:40 +01:00
}
2006-05-06 17:30:34 +02:00
2010-05-12 13:29:21 +02:00
/*
* Add file in email form
*/
2012-07-11 18:13:41 +02:00
if ( GETPOST ( 'addfile' ))
2010-05-12 13:29:21 +02:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2010-05-12 13:29:21 +02:00
2011-10-14 16:44:22 +02:00
// Set tmp user directory TODO Use a dedicated directory for temp mails files
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir_tmp = $vardir . '/temp' ;
2010-05-12 13:29:21 +02:00
2012-07-29 12:54:19 +02:00
dol_add_file_process ( $upload_dir_tmp , 0 , 0 );
2011-10-14 16:44:22 +02:00
$action = 'presend' ;
2010-05-12 13:29:21 +02:00
}
/*
* Remove file in email form
*/
2012-07-11 18:13:41 +02:00
if ( GETPOST ( 'removedfile' ))
2010-05-12 13:29:21 +02:00
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2010-05-12 13:29:21 +02:00
2011-10-14 16:44:22 +02:00
// Set tmp user directory
$vardir = $conf -> user -> dir_output . " / " . $user -> id ;
$upload_dir_tmp = $vardir . '/temp' ;
2010-05-12 13:29:21 +02:00
2011-12-22 09:07:02 +01:00
// TODO Delete only files that was uploaded from email form
2012-07-29 12:54:19 +02:00
dol_remove_file_process ( $_POST [ 'removedfile' ], 0 );
2011-10-14 16:44:22 +02:00
$action = 'presend' ;
2010-05-12 13:29:21 +02:00
}
/*
* Send mail
*/
2012-07-13 10:15:47 +02:00
if ( $action == 'send' && ! GETPOST ( 'addfile' ) && ! GETPOST ( 'removedfile' ) && ! GETPOST ( 'cancel' ))
2010-05-12 13:29:21 +02:00
{
2011-10-14 16:44:22 +02:00
$langs -> load ( 'mails' );
2012-12-01 15:45:05 +01:00
if ( $object -> id > 0 )
2011-10-14 16:44:22 +02:00
{
2012-03-16 00:34:41 +01:00
// $ref = dol_sanitizeFileName($object->ref);
// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
2011-10-14 16:44:22 +02:00
2012-03-16 00:34:41 +01:00
// if (is_readable($file))
// {
2013-03-23 14:39:23 +01:00
if ( GETPOST ( 'sendto' , 'alpha' ))
2011-10-14 16:44:22 +02:00
{
// Le destinataire a ete fourni via le champ libre
2013-03-23 14:39:23 +01:00
$sendto = GETPOST ( 'sendto' , 'alpha' );
2011-10-14 16:44:22 +02:00
$sendtoid = 0 ;
}
2013-03-23 14:39:23 +01:00
elseif ( GETPOST ( 'receiver' , 'alpha' ) != '-1' )
2011-07-07 23:32:18 +02:00
{
// Recipient was provided from combo list
2013-03-23 14:39:23 +01:00
if ( GETPOST ( 'receiver' , 'alpha' ) == 'thirdparty' ) // Id of third party
2011-10-14 16:44:22 +02:00
{
$sendto = $object -> client -> email ;
$sendtoid = 0 ;
}
else // Id du contact
{
2013-03-23 14:39:23 +01:00
$sendto = $object -> client -> contact_get_property ( GETPOST ( 'receiver' , 'alpha' ), 'email' );
$sendtoid = GETPOST ( 'receiver' , 'alpha' );
2011-10-14 16:44:22 +02:00
}
}
if ( dol_strlen ( $sendto ))
{
$langs -> load ( " commercial " );
2013-03-23 14:39:23 +01:00
$from = GETPOST ( 'fromname' , 'alpha' ) . ' <' . GETPOST ( 'frommail' , 'alpha' ) . '>' ;
$replyto = GETPOST ( 'replytoname' , 'alpha' ) . ' <' . GETPOST ( 'replytomail' , 'alpha' ) . '>' ;
$message = GETPOST ( 'message' );
$sendtocc = GETPOST ( 'sendtocc' , 'alpha' );
$deliveryreceipt = GETPOST ( 'deliveryreceipt' , 'alpha' );
2011-10-14 16:44:22 +02:00
if ( $action == 'send' )
{
2013-03-23 14:39:23 +01:00
if ( dol_strlen ( GETPOST ( 'subject' ))) $subject = GETPOST ( 'subject' );
2011-10-14 16:44:22 +02:00
else $subject = $langs -> transnoentities ( 'CustomerOrder' ) . ' ' . $object -> 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
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
2011-10-14 16:44:22 +02:00
$formmail = new FormMail ( $db );
$attachedfiles = $formmail -> get_attached_files ();
$filepath = $attachedfiles [ 'paths' ];
$filename = $attachedfiles [ 'names' ];
$mimetype = $attachedfiles [ 'mimes' ];
// Send mail
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2013-03-23 14:39:23 +01:00
$mailfile = new CMailFile ( $subject , $sendto , $from , $message , $filepath , $mimetype , $filename , $sendtocc , '' , $deliveryreceipt , - 1 );
2011-10-14 16:44:22 +02:00
if ( $mailfile -> error )
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $mailfile -> error , 'errors' );
2011-10-14 16:44:22 +02:00
}
else
{
$result = $mailfile -> sendfile ();
if ( $result )
{
2012-12-01 15:45:05 +01:00
$mesg = $langs -> trans ( 'MailSuccessfulySent' , $mailfile -> getValidAddress ( $from , 2 ), $mailfile -> getValidAddress ( $sendto , 2 )); // Must not contain "
setEventMessage ( $mesg );
2011-10-14 16:44:22 +02:00
$error = 0 ;
// Initialisation donnees
$object -> sendtoid = $sendtoid ;
$object -> actiontypecode = $actiontypecode ;
$object -> actionmsg = $actionmsg ;
$object -> actionmsg2 = $actionmsg2 ;
$object -> fk_element = $object -> id ;
$object -> elementtype = $object -> element ;
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2011-10-14 16:44:22 +02:00
$interface = new Interfaces ( $db );
$result = $interface -> run_triggers ( 'ORDER_SUPPLIER_SENTBYMAIL' , $object , $user , $langs , $conf );
2012-01-19 09:53:27 +01:00
if ( $result < 0 ) { $error ++ ; $errors = $interface -> errors ; }
2011-10-14 16:44:22 +02:00
// Fin appel triggers
if ( $error )
{
dol_print_error ( $db );
}
else
{
// Redirect here
2013-03-24 21:06:45 +01:00
// This avoid sending mail twice if going out and then back to page
2013-03-23 14:39:23 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
2011-10-14 16:44:22 +02:00
exit ;
}
}
else
{
$langs -> load ( " other " );
if ( $mailfile -> error )
{
2012-12-01 15:45:05 +01:00
$mesg = $langs -> trans ( 'ErrorFailedToSendMail' , $from , $sendto );
$mesg .= '<br>' . $mailfile -> error ;
2011-10-14 16:44:22 +02:00
}
else
{
2012-12-01 15:45:05 +01:00
$mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS' ;
2011-10-14 16:44:22 +02:00
}
2012-12-01 15:45:05 +01:00
setEventMessage ( $mesg , 'errors' );
2011-10-14 16:44:22 +02:00
}
}
2012-03-16 00:34:41 +01:00
/* }
2011-10-14 16:44:22 +02:00
else
{
$langs -> load ( " other " );
$mesg = '<div class="error">' . $langs -> trans ( 'ErrorMailRecipientIsEmpty' ) . ' !</div>' ;
$action = 'presend' ;
dol_syslog ( 'Recipient email is empty' );
2012-03-16 00:34:41 +01:00
} */
2011-10-14 16:44:22 +02:00
}
else
{
2011-10-29 23:52:05 +02:00
$langs -> load ( " errors " );
2012-12-01 15:45:05 +01:00
setEventMessage ( $langs -> trans ( 'ErrorCantReadFile' , $file ), 'errors' );
2011-10-14 16:44:22 +02:00
dol_syslog ( 'Failed to read file: ' . $file );
}
}
else
{
$langs -> load ( " other " );
2012-12-01 15:45:05 +01:00
setEventMessage ( $langs -> trans ( 'ErrorFailedToReadEntity' , $langs -> trans ( " Invoice " )), 'errors' );
2011-10-14 16:44:22 +02:00
dol_syslog ( 'Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.' );
}
2010-05-12 13:29:21 +02:00
}
2012-10-18 10:35:55 +02:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ) && $user -> rights -> fournisseur -> commande -> creer )
2012-03-18 11:13:01 +01:00
{
2012-10-18 10:35:55 +02:00
if ( $action == 'addcontact' )
2012-04-10 17:21:28 +02:00
{
2012-12-01 15:45:05 +01:00
if ( $object -> id > 0 )
2012-04-10 17:21:28 +02:00
{
$contactid = ( GETPOST ( 'userid' ) ? GETPOST ( 'userid' ) : GETPOST ( 'contactid' ));
2012-12-01 15:45:05 +01:00
$result = $object -> add_contact ( $contactid , $_POST [ " type " ], $_POST [ " source " ]);
2012-04-10 17:21:28 +02:00
}
if ( $result >= 0 )
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2012-04-10 17:21:28 +02:00
exit ;
}
else
{
if ( $object -> error == 'DB_ERROR_RECORD_ALREADY_EXISTS' )
{
$langs -> load ( " errors " );
2012-12-01 15:45:05 +01:00
setEventMessage ( $langs -> trans ( " ErrorThisContactIsAlreadyDefinedAsThisType " ), 'errors' );
2012-04-10 17:21:28 +02:00
}
else
{
2012-12-01 15:45:05 +01:00
setEventMessage ( $object -> error , 'errors' );
2012-04-10 17:21:28 +02:00
}
}
}
// bascule du statut d'un contact
2012-12-01 15:45:05 +01:00
else if ( $action == 'swapstatut' && $object -> id > 0 )
2012-04-10 17:21:28 +02:00
{
2012-12-01 15:45:05 +01:00
$result = $object -> swapContactStatus ( GETPOST ( 'ligne' ));
2012-04-10 17:21:28 +02:00
}
// Efface un contact
2012-12-01 15:45:05 +01:00
else if ( $action == 'deletecontact' && $object -> id > 0 )
2012-04-10 17:21:28 +02:00
{
$result = $object -> delete_contact ( $_GET [ " lineid " ]);
if ( $result >= 0 )
2012-03-18 14:06:55 +01:00
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id );
2012-04-10 17:21:28 +02:00
exit ;
}
else {
dol_print_error ( $db );
}
2012-03-18 11:13:01 +01:00
}
}
2006-05-06 17:30:34 +02:00
2008-07-04 19:36:18 +02:00
/*
* View
*/
2006-12-05 01:47:40 +01:00
llxHeader ( '' , $langs -> trans ( " OrderCard " ), " CommandeFournisseur " );
2006-05-06 17:30:34 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2008-01-20 14:53:02 +01:00
$formfile = new FormFile ( $db );
2008-11-16 02:54:33 +01:00
$formorder = new FormOrder ( $db );
2010-05-12 13:29:21 +02:00
$productstatic = new Product ( $db );
2006-05-06 17:30:34 +02:00
2008-05-09 11:08:41 +02:00
/* *************************************************************************** */
/* */
/* Mode vue et edition */
/* */
/* *************************************************************************** */
2010-05-12 13:29:21 +02:00
$now = dol_now ();
2013-03-12 15:06:38 +01:00
if ( $action == " create " )
{
print_fiche_titre ( $langs -> trans ( 'NewOrder' ));
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
dol_htmloutput_mesg ( $mesg );
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
$societe = '' ;
if ( $socid > 0 )
{
$societe = new Societe ( $db );
$societe -> fetch ( $socid );
}
2013-11-17 23:25:25 +01:00
2013-07-30 16:21:39 +02:00
$cond_reglement_id = $societe -> cond_reglement_supplier_id ;
$mode_reglement_id = $societe -> mode_reglement_supplier_id ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
print '<form name="add" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="add">' ;
print '<table class="border" width="100%">' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
// Ref
print '<tr><td>' . $langs -> trans ( 'Ref' ) . '</td><td>' . $langs -> trans ( 'Draft' ) . '</td></tr>' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
// Third party
print '<tr><td class="fieldrequired">' . $langs -> trans ( 'Supplier' ) . '</td>' ;
print '<td>' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
if ( $socid > 0 )
{
print $societe -> getNomUrl ( 1 );
print '<input type="hidden" name="socid" value="' . $socid . '">' ;
}
else
{
print $form -> select_company (( empty ( $socid ) ? '' : $socid ), 'socid' , 's.fournisseur = 1' , 1 );
}
print '</td>' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
// Ref supplier
print '<tr><td>' . $langs -> trans ( 'RefSupplier' ) . '</td><td><input name="refsupplier" type="text"></td>' ;
print '</tr>' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
print '</td></tr>' ;
2013-11-17 23:25:25 +01:00
2013-07-30 16:21:39 +02:00
// Payment term
print '<tr><td class="nowrap">' . $langs -> trans ( 'PaymentConditionsShort' ) . '</td><td colspan="2">' ;
$form -> select_conditions_paiements ( isset ( $_POST [ 'cond_reglement_id' ]) ? $_POST [ 'cond_reglement_id' ] : $cond_reglement_id , 'cond_reglement_id' );
print '</td></tr>' ;
// Payment mode
print '<tr><td>' . $langs -> trans ( 'PaymentMode' ) . '</td><td colspan="2">' ;
$form -> select_types_paiements ( isset ( $_POST [ 'mode_reglement_id' ]) ? $_POST [ 'mode_reglement_id' ] : $mode_reglement_id , 'mode_reglement_id' );
print '</td></tr>' ;
2013-04-16 01:13:20 +02:00
2013-04-09 17:18:07 +02:00
print '<tr><td>' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td>' ;
$doleditor = new DolEditor ( 'note_public' , GETPOST ( 'note_public' ), '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 );
print '</td>' ;
//print '<textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea>';
2013-03-12 15:06:38 +01:00
print '</tr>' ;
2013-03-24 21:06:45 +01:00
2013-04-09 17:18:07 +02:00
print '<tr><td>' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td>' ;
$doleditor = new DolEditor ( 'note_private' , GETPOST ( 'note_private' ), '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , 70 );
print $doleditor -> Create ( 1 );
print '</td>' ;
//print '<td><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
2013-03-12 15:06:38 +01:00
print '</tr>' ;
2013-03-24 21:06:45 +01:00
2013-04-16 01:13:20 +02:00
2013-04-09 17:18:07 +02:00
2013-03-12 15:06:38 +01:00
// Other options
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2013-12-16 11:13:39 +01:00
if ( empty ( $reshook ) && ! empty ( $extrafields -> attribute_label ))
{
print $object -> showOptionals ( $extrafields , 'edit' );
}
2013-03-12 15:06:38 +01:00
// Bouton "Create Draft"
print " </table> \n " ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
print '<br><center><input type="submit" class="button" name="bouton" value="' . $langs -> trans ( 'CreateDraft' ) . '"></center>' ;
2013-03-24 21:06:45 +01:00
2013-03-12 15:06:38 +01:00
print " </form> \n " ;
}
elseif ( ! empty ( $object -> id ))
2006-12-05 01:47:40 +01:00
{
2012-12-01 15:45:05 +01:00
$author = new User ( $db );
$author -> fetch ( $object -> user_author_id );
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$head = ordersupplier_prepare_head ( $object );
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$title = $langs -> trans ( " SupplierOrder " );
dol_fiche_head ( $head , 'card' , $title , 0 , 'order' );
2013-12-16 11:13:39 +01:00
$res = $object -> fetch_optionals ( $object -> id , $extralabels );
2012-12-01 15:45:05 +01:00
/*
* Confirmation de la suppression de la commande
*/
if ( $action == 'delete' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteOrder' ), $langs -> trans ( 'ConfirmDeleteOrder' ), 'confirm_delete' , '' , 0 , 2 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-11-09 22:10:58 +01:00
2012-12-01 15:45:05 +01:00
// Clone confirmation
if ( $action == 'clone' )
{
// Create an array for form
$formquestion = array (
//array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1)
);
// Paiement incomplet. On demande si motif = escompte ou autre
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'CloneOrder' ), $langs -> trans ( 'ConfirmCloneOrder' , $object -> ref ), 'confirm_clone' , $formquestion , 'yes' , 1 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de la validation
*/
if ( $action == 'valid' )
{
$object -> date_commande = dol_now ();
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// We check if number is temporary number
if ( preg_match ( '/^[\(]?PROV/i' , $object -> ref )) $newref = $object -> getNextNumRef ( $object -> thirdparty );
else $newref = $object -> ref ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$text = $langs -> trans ( 'ConfirmValidateOrder' , $newref );
if ( ! empty ( $conf -> notification -> enabled ))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
$notify = new Notify ( $db );
$text .= '<br>' ;
2013-04-21 14:24:19 +02:00
$text .= $notify -> confirmMessage ( 'ORDER_SUPPLIER_APPROVE' , $object -> socid );
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id , $langs -> trans ( 'ValidateOrder' ), $text , 'confirm_valid' , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de l ' approbation
*/
if ( $action == 'approve' )
{
$formquestion = array ();
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER ) && $object -> hasProductsOrServices ( 1 ))
{
$langs -> load ( " stocks " );
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
$formproduct = new FormProduct ( $db );
$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),
2013-06-08 21:57:57 +02:00
array ( 'type' => 'other' , 'name' => 'idwarehouse' , 'label' => $langs -> trans ( " SelectWarehouseForStockIncrease " ), 'value' => $formproduct -> selectWarehouses ( GETPOST ( 'idwarehouse' ), 'idwarehouse' , '' , 1 ))
2012-12-01 15:45:05 +01:00
);
}
2011-10-14 16:44:22 +02:00
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id , $langs -> trans ( " ApproveThisOrder " ), $langs -> trans ( " ConfirmApproveThisOrder " , $object -> ref ), " confirm_approve " , $formquestion , 1 , 1 , 240 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de la desapprobation
*/
if ( $action == 'refuse' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= $object->id " , $langs -> trans ( " DenyingThisOrder " ), $langs -> trans ( " ConfirmDenyingThisOrder " , $object -> ref ), " confirm_refuse " , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2012-04-10 17:21:28 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de l ' annulation
*/
if ( $action == 'cancel' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= $object->id " , $langs -> trans ( " Cancel " ), $langs -> trans ( " ConfirmCancelThisOrder " , $object -> ref ), " confirm_cancel " , '' , 0 , 1 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de l ' envoi de la commande
*/
if ( $action == 'commande' )
{
$date_com = dol_mktime ( 0 , 0 , 0 , $_POST [ " remonth " ], $_POST [ " reday " ], $_POST [ " reyear " ]);
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . " ?id= " . $object -> id . " &datecommande= " . $date_com . " &methode= " . $_POST [ " methodecommande " ] . " &comment= " . urlencode ( $_POST [ " comment " ]), $langs -> trans ( " MakeOrder " ), $langs -> trans ( " ConfirmMakeOrder " , dol_print_date ( $date_com , 'day' )), " confirm_commande " , '' , 0 , 2 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
2012-12-01 15:45:05 +01:00
/*
* Confirmation de la suppression d ' une ligne produit
*/
if ( $action == 'delete_product_line' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&lineid=' . $_GET [ " lineid " ], $langs -> trans ( 'DeleteProductLine' ), $langs -> trans ( 'ConfirmDeleteProductLine' ), 'confirm_deleteproductline' , '' , 0 , 2 );
2013-11-17 23:25:25 +01:00
2012-12-01 15:45:05 +01:00
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Commande
*/
$nbrow = 8 ;
if ( ! empty ( $conf -> projet -> enabled )) $nbrow ++ ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
//Local taxes
2013-01-05 09:43:40 +01:00
//TODO: Place into a function to control showing by country or study better option
2012-12-01 15:45:05 +01:00
if ( $mysoc -> country_code == 'ES' )
{
if ( $mysoc -> localtax1_assuj == " 1 " ) $nbrow ++ ;
2013-01-05 09:47:54 +01:00
if ( $object -> thirdparty -> localtax2_assuj == " 1 " ) $nbrow ++ ;
2012-12-01 15:45:05 +01:00
}
2013-01-07 00:40:18 +01:00
else
2012-12-01 15:45:05 +01:00
{
if ( $mysoc -> localtax1_assuj == " 1 " ) $nbrow ++ ;
if ( $mysoc -> localtax2_assuj == " 1 " ) $nbrow ++ ;
}
print '<table class="border" width="100%">' ;
$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/commande/liste.php' . ( ! empty ( $socid ) ? '?socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
// Ref
print '<tr><td width="20%">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td colspan="2">' ;
print $form -> showrefnav ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' );
print '</td>' ;
print '</tr>' ;
// Ref supplier
print '<tr><td>' ;
2013-11-28 15:54:12 +01:00
print $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> fournisseur -> commande -> creer );
2012-12-01 15:45:05 +01:00
print '</td><td colspan="2">' ;
2013-11-28 15:54:12 +01:00
print $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , $user -> rights -> fournisseur -> commande -> creer );
2012-12-01 15:45:05 +01:00
print '</td></tr>' ;
// Fournisseur
print '<tr><td>' . $langs -> trans ( " Supplier " ) . " </td> " ;
print '<td colspan="2">' . $object -> thirdparty -> getNomUrl ( 1 , 'supplier' ) . '</td>' ;
print '</tr>' ;
// Statut
print '<tr>' ;
print '<td>' . $langs -> trans ( " Status " ) . '</td>' ;
print '<td colspan="2">' ;
print $object -> getLibStatut ( 4 );
print " </td></tr> " ;
// Date
if ( $object -> methode_commande_id > 0 )
{
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td><td colspan="2">' ;
if ( $object -> date_commande )
{
print dol_print_date ( $object -> date_commande , " dayhourtext " ) . " \n " ;
}
print " </td></tr> " ;
2012-03-22 23:52:02 +01:00
2012-12-01 15:45:05 +01:00
if ( $object -> methode_commande )
{
print '<tr><td>' . $langs -> trans ( " Method " ) . '</td><td colspan="2">' . $object -> getInputMethod () . '</td></tr>' ;
}
}
2012-04-10 17:21:28 +02:00
2012-12-01 15:45:05 +01:00
// Author
print '<tr><td>' . $langs -> trans ( " AuthorRequest " ) . '</td>' ;
print '<td colspan="2">' . $author -> getNomUrl ( 1 ) . '</td>' ;
print '</tr>' ;
// Conditions de reglement par defaut
$langs -> load ( 'bills' );
2013-07-19 14:23:42 +02:00
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
2012-12-01 15:45:05 +01:00
print $langs -> trans ( 'PaymentConditions' );
print '<td>' ;
if ( $action != 'editconditions' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editconditions&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetConditions' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
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 " </td> " ;
print '</tr>' ;
// Mode of payment
$langs -> load ( 'bills' );
2013-07-19 14:23:42 +02:00
print '<tr><td class="nowrap">' ;
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">' ;
2012-12-01 15:45:05 +01:00
print $langs -> trans ( 'PaymentMode' );
print '</td>' ;
if ( $action != 'editmode' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editmode&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetMode' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
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 '</td></tr>' ;
// Delivery date planed
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'DateDeliveryPlanned' );
print '</td>' ;
if ( $action != 'editdate_livraison' ) print '<td align="right"><a href="' . $_SERVER [ " PHP_SELF " ] . '?action=editdate_livraison&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetDeliveryDate' ), 1 ) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
if ( $action == 'editdate_livraison' )
{
print '<form name="setdate_livraison" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setdate_livraison">' ;
$form -> select_date ( $object -> date_livraison ? $object -> date_livraison :- 1 , 'liv_' , '' , '' , '' , " setdate_livraison " );
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
}
else
{
print $object -> date_livraison ? dol_print_date ( $object -> date_livraison , 'daytext' ) : ' ' ;
}
print '</td>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
$langs -> load ( 'projects' );
print '<tr><td height="10">' ;
print '<table class="nobordernopadding" width="100%"><tr><td>' ;
print $langs -> trans ( 'Project' );
print '</td>' ;
if ( $action != 'classify' ) print '<td align="right"><a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> trans ( 'SetProject' )) . '</a></td>' ;
print '</tr></table>' ;
print '</td><td colspan="2">' ;
//print "$object->id, $object->socid, $object->fk_project";
if ( $action == 'classify' )
{
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , empty ( $conf -> global -> PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS ) ? $object -> socid : '-1' , $object -> fk_project , 'projectid' );
}
else
{
$form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' );
}
print '</td>' ;
print '</tr>' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Other attributes
$parameters = array ( 'socid' => $socid , 'colspan' => ' colspan="3"' );
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2013-12-16 11:13:39 +01:00
if ( empty ( $reshook ) && ! empty ( $extrafields -> attribute_label ))
{
2011-10-14 16:44:22 +02:00
2013-12-16 11:13:39 +01:00
if ( $action == 'edit_extras' )
{
print '<form enctype="multipart/form-data" action="' . $_SERVER [ " PHP_SELF " ] . '" method="post" name="formsoc">' ;
print '<input type="hidden" name="action" value="update_extras">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="id" value="' . $object -> id . '">' ;
}
foreach ( $extrafields -> attribute_label as $key => $label )
{
if ( $action == 'edit_extras' ) {
$value = ( isset ( $_POST [ " options_ " . $key ]) ? $_POST [ " options_ " . $key ] : $object -> array_options [ " options_ " . $key ]);
} else {
$value = $object -> array_options [ " options_ " . $key ];
}
if ( $extrafields -> attribute_type [ $key ] == 'separate' )
{
print $extrafields -> showSeparator ( $key );
}
else
{
print '<tr><td' ;
if ( ! empty ( $extrafields -> attribute_required [ $key ])) print ' class="fieldrequired"' ;
print '>' . $label . '</td><td colspan="5">' ;
// Convert date into timestamp format
if ( in_array ( $extrafields -> attribute_type [ $key ], array ( 'date' , 'datetime' )))
{
$value = isset ( $_POST [ " options_ " . $key ]) ? dol_mktime ( $_POST [ " options_ " . $key . " hour " ], $_POST [ " options_ " . $key . " min " ], 0 , $_POST [ " options_ " . $key . " month " ], $_POST [ " options_ " . $key . " day " ], $_POST [ " options_ " . $key . " year " ]) : $db -> jdate ( $object -> array_options [ 'options_' . $key ]);
}
if ( $action == 'edit_extras' && $user -> rights -> fournisseur -> commande -> creer )
{
print $extrafields -> showInputField ( $key , $value );
}
else
{
print $extrafields -> showOutputField ( $key , $value );
}
print '</td></tr>' . " \n " ;
}
}
if ( count ( $extrafields -> attribute_label ) > 0 ) {
if ( $action == 'edit_extras' && $user -> rights -> fournisseur -> commande -> creer )
{
print '<tr><td></td><td colspan="5">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( 'Modify' ) . '">' ;
print '</form>' ;
print '</td></tr>' ;
}
else {
if ( $object -> statut == 0 && $user -> rights -> fournisseur -> commande -> creer )
{
print '<tr><td></td><td><a href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&action=edit_extras">' . img_picto ( '' , 'edit' ) . ' ' . $langs -> trans ( 'Modify' ) . '</a></td></tr>' ;
}
}
}
}
2012-12-01 15:45:05 +01:00
// Ligne de 3 colonnes
print '<tr><td>' . $langs -> trans ( " AmountHT " ) . '</td>' ;
print '<td align="right"><b>' . price ( $object -> total_ht ) . '</b></td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '<tr><td>' . $langs -> trans ( " AmountVAT " ) . '</td><td align="right">' . price ( $object -> total_tva ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Amount Local Taxes
2013-01-05 09:43:40 +01:00
//TODO: Place into a function to control showing by country or study better option
2012-12-01 15:45:05 +01:00
if ( $mysoc -> country_code == 'ES' )
{
if ( $mysoc -> localtax1_assuj == " 1 " ) //Localtax1 RE
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td>' ;
print '<td align="right">' . price ( $object -> total_localtax1 ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
}
2013-01-05 09:43:40 +01:00
if ( $object -> thirdparty -> localtax2_assuj == " 1 " ) //Localtax2 IRPF
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td>' ;
print '<td align="right">' . price ( $object -> total_localtax2 ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
}
}
2013-01-07 00:40:18 +01:00
else
2013-01-05 09:43:40 +01:00
{
if ( $mysoc -> localtax1_assuj == " 1 " ) //Localtax1
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td>' ;
print '<td align="right">' . price ( $object -> total_localtax1 ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
}
if ( $mysoc -> localtax2_assuj == " 1 " ) //Localtax2
2012-12-01 15:45:05 +01:00
{
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td>' ;
print '<td align="right">' . price ( $object -> total_localtax2 ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
}
}
print '<tr><td>' . $langs -> trans ( " AmountTTC " ) . '</td><td align="right">' . price ( $object -> total_ttc ) . '</td>' ;
print '<td>' . $langs -> trans ( " Currency " . $conf -> currency ) . '</td></tr>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print " </table><br> " ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_CONTACTS_TAB ))
{
$blocname = 'contacts' ;
$title = $langs -> trans ( 'ContactsAddresses' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( ! empty ( $conf -> global -> MAIN_DISABLE_NOTES_TAB ))
{
$blocname = 'notes' ;
$title = $langs -> trans ( 'Notes' );
include DOL_DOCUMENT_ROOT . '/core/tpl/bloc_showhide.tpl.php' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Lines
2013-11-17 23:25:25 +01:00
*/
print ' <form name="addproduct" id="addproduct" action="' . $_SERVER [ " PHP_SELF " ] . '?etat=1&id=' . $object -> id . (( $action != 'edit_line' ) ? '#add' : '#line_' . GETPOST ( 'lineid' )) . ' " method= " POST " >
< input type = " hidden " name = " token " value = " '. $_SESSION['newtoken'] .' " >
< input type = " hidden " name = " action " value = " '.(( $action != 'edit_line')?'addline':'update_line').' " >
< input type = " hidden " name = " mode " value = " " >
< input type = " hidden " name = " id " value = " '. $object->id .' " >
< input type = " hidden " name = " facid " value = " '. $object->id .' " >
< input type = " hidden " name = " socid " value = " '. $societe->id .' " >
' ;
print '<table id="tablelines" class="noborder noshadow" width="100%">' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$num = count ( $object -> lines );
$i = 0 ; $total = 0 ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( $num )
{
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( 'Label' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right" width="80">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td align="right" width="50">' . $langs -> trans ( 'TotalHTShort' ) . '</td>' ;
print '<td width="48" colspan="3"> </td>' ;
print " </tr> \n " ;
}
$var = true ;
while ( $i < $num )
{
$line = $object -> lines [ $i ];
$var =! $var ;
// Show product and description
$type = ( ! empty ( $line -> product_type ) ? $line -> product_type : ( ! empty ( $line -> fk_product_type ) ? $line -> fk_product_type : 0 ));
// Try to enhance type detection using date_start and date_end for free lines where type
// was not saved.
$date_start = '' ;
$date_end = '' ;
if ( ! empty ( $line -> date_start ))
{
$date_start = $line -> date_start ;
$type = 1 ;
}
if ( ! empty ( $line -> date_end ))
{
$date_end = $line -> date_end ;
$type = 1 ;
}
2011-10-14 16:44:22 +02:00
2013-11-17 23:25:25 +01:00
// Edit line
if ( $action != 'edit_line' || $_GET [ 'rowid' ] != $line -> id )
2012-12-01 15:45:05 +01:00
{
print '<tr ' . $bc [ $var ] . '>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Show product and description
print '<td>' ;
if ( $line -> fk_product > 0 )
{
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$product_static = new ProductFournisseur ( $db );
$product_static -> fetch ( $line -> fk_product );
$text = $product_static -> getNomUrl ( 1 , 'supplier' );
$text .= ' - ' . $product_static -> libelle ;
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> description ));
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Show range
print_date_range ( $date_start , $date_end );
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Add description in form
if ( ! empty ( $conf -> global -> PRODUIT_DESC_IN_FORM )) print ( $line -> description && $line -> description != $product_static -> libelle ) ? '<br>' . dol_htmlentitiesbr ( $line -> description ) : '' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Description - Editor wysiwyg
if ( ! $line -> fk_product )
{
if ( $type == 1 ) $text = img_object ( $langs -> trans ( 'Service' ), 'service' );
else $text = img_object ( $langs -> trans ( 'Product' ), 'product' );
print $text . ' ' . nl2br ( $line -> description );
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Show range
print_date_range ( $date_start , $date_end );
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '</td>' ;
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . vatrate ( $line -> tva_tx ) . '%</td>' ;
2011-10-14 16:44:22 +02:00
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . price ( $line -> subprice ) . " </td> \n " ;
2011-10-14 16:44:22 +02:00
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . $line -> qty . '</td>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( $line -> remise_percent > 0 )
{
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . dol_print_reduction ( $line -> remise_percent , $langs ) . " </td> \n " ;
2012-12-01 15:45:05 +01:00
}
else
{
print '<td> </td>' ;
}
Add: hooks and triggers for a lot of core modules (action/calendrier, deplacement, dons, tva, contact/tiers, contrat, product lines, expedition, fournisseur commandes et factures, fiche intervention, projet et taches)
Signed-off-by: Stephen L. <lrq3000@gmail.com>
2012-08-14 15:50:45 +02:00
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap">' . price ( $line -> total_ht ) . '</td>' ;
2012-12-01 15:45:05 +01:00
if ( $object -> statut == 0 && $user -> rights -> fournisseur -> commande -> creer )
{
2013-11-17 23:25:25 +01:00
print '<td align="center"><a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit_line&rowid=' . $line -> id . '#' . $line -> id . '">' ;
2012-12-01 15:45:05 +01:00
print img_edit ();
print '</a></td>' ;
$actiondelete = 'delete_product_line' ;
print '<td align="center"><a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=' . $actiondelete . '&lineid=' . $line -> id . '">' ;
print img_delete ();
print '</a></td>' ;
}
else
{
print '<td> </td><td> </td>' ;
}
print " </tr> " ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Ligne en mode update
2013-11-17 23:25:25 +01:00
if ( $action == 'edit_line' && $user -> rights -> fournisseur -> commande -> creer && ( $_GET [ " rowid " ] == $line -> id ))
2012-12-01 15:45:05 +01:00
{
print " \n " ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' ;
2013-11-17 23:25:25 +01:00
print '<input type="hidden" name="elrowid" value="' . $_GET [ 'rowid' ] . '">' ;
2012-12-01 15:45:05 +01:00
print '<a name="' . $line -> id . '"></a>' ; // ancre pour retourner sur la ligne
if (( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled )) && $line -> fk_product > 0 )
{
$product_static = new ProductFournisseur ( $db );
$product_static -> fetch ( $line -> fk_product );
$text = $product_static -> getNomUrl ( 1 , 'supplier' );
$text .= ' - ' . $product_static -> libelle ;
$description = ( $conf -> global -> PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr ( $line -> description ));
print $form -> textwithtooltip ( $text , $description , 3 , '' , '' , $i );
// Show range
print_date_range ( $date_start , $date_end );
print '<br>' ;
}
else
{
print $form -> select_type_of_lines ( $line -> product_type , 'type' , 1 );
if ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled )) print '<br>' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( is_object ( $hookmanager ))
{
$parameters = array ( 'fk_parent_line' => $line -> fk_parent_line , 'line' => $line , 'var' => $var , 'num' => $num , 'i' => $i );
$reshook = $hookmanager -> executeHooks ( 'formEditProductOptions' , $parameters , $object , $action );
}
2013-04-16 01:13:20 +02:00
2012-12-01 15:45:05 +01:00
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
$doleditor = new DolEditor ( 'eldesc' , $line -> description , '' , 200 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , $nbrows , 70 );
$doleditor -> Create ();
print '</td>' ;
print '<td>' ;
print $form -> load_tva ( 'tva_tx' , $line -> tva_tx , $object -> thirdparty , $mysoc );
print '</td>' ;
print '<td align="right"><input size="5" type="text" name="pu" value="' . price ( $line -> subprice ) . '"></td>' ;
print '<td align="right"><input size="2" type="text" name="qty" value="' . $line -> qty . '"></td>' ;
2013-04-25 01:13:13 +02:00
print '<td align="right" class="nowrap"><input size="1" type="text" name="remise_percent" value="' . $line -> remise_percent . '"><span class="hideonsmartphone">%</span></td>' ;
2012-12-01 15:45:05 +01:00
print '<td align="center" colspan="4"><input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print '<br><input type="submit" class="button" name="cancel" value="' . $langs -> trans ( 'Cancel' ) . '"></td>' ;
print '</tr>' . " \n " ;
}
$i ++ ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Form to add new line
*/
2013-11-17 23:25:25 +01:00
if ( $object -> statut == 0 && $user -> rights -> fournisseur -> commande -> creer && $action <> 'edit_line' )
2012-12-01 15:45:05 +01:00
{
print '<tr class="liste_titre">' ;
print '<td>' ;
print '<a name="add"></a>' ; // ancre
print $langs -> trans ( 'AddNewLine' ) . ' - ' . $langs -> trans ( " FreeZone " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'VAT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
// TODO Use the predefinedproductline_create.tpl.php file
// Add free products/services form
$var = true ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$forceall = 1 ;
print $form -> select_type_of_lines ( isset ( $_POST [ " type " ]) ? $_POST [ " type " ] :- 1 , 'type' , 1 , 0 , $forceall );
if ( $forceall || ( ! empty ( $conf -> product -> enabled ) && ! empty ( $conf -> service -> enabled ))
|| ( empty ( $conf -> product -> enabled ) && empty ( $conf -> service -> enabled ))) print '<br>' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( is_object ( $hookmanager ))
{
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formCreateProductOptions' , $parameters , $object , $action );
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
$doleditor = new DolEditor ( 'dp_desc' , GETPOST ( 'dp_desc' ), '' , 100 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , $nbrows , 70 );
$doleditor -> Create ();
print '</td>' ;
print '<td align="center">' ;
print $form -> load_tva ( 'tva_tx' ,( GETPOST ( 'tva_tx' ) ? GETPOST ( 'tva_tx' ) :- 1 ), $object -> thirdparty , $mysoc );
print '</td>' ;
print '<td align="right"><input type="text" name="pu" size="5" value="' . GETPOST ( 'pu' ) . '"></td>' ;
print '<td align="right"><input type="text" name="qty" value="' . ( GETPOST ( 'qty' ) ? GETPOST ( 'qty' ) : '1' ) . '" size="2"></td>' ;
2013-06-16 21:31:21 +02:00
print '<td align="right" class="nowrap"><input type="text" name="remise_percent" size="1" value="' . ( GETPOST ( 'remise_percent' ) ? GETPOST ( 'remise_percent' ) : $object -> thirdparty -> remise_percent ) . '"><span class="hideonsmartphone">%</span></td>' ;
2013-11-17 23:25:25 +01:00
print '<td align="center" colspan="4"><input type="submit" class="button" value="' . $langs -> trans ( 'Add' ) . '" name="addline_libre"></td>' ;
2012-12-01 15:45:05 +01:00
print '</tr>' ;
// Ajout de produits/services predefinis
if ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))
{
2013-11-17 23:25:25 +01:00
print ' < script type = " text/javascript " >
jQuery ( document ) . ready ( function () {
jQuery ( \ ' #idprodfournprice\').change(function() {
if ( jQuery ( \ ' #idprodfournprice\').val() > 0) jQuery(\'#np_desc\').focus();
});
});
</ script > ' ;
2012-12-01 15:45:05 +01:00
print '<tr class="liste_titre">' ;
print '<td colspan="3">' ;
print $langs -> trans ( " AddNewLine " ) . ' - ' ;
if ( ! empty ( $conf -> service -> enabled ))
{
print $langs -> trans ( 'RecordedProductsAndServices' );
}
else
{
print $langs -> trans ( 'RecordedProducts' );
}
print '</td>' ;
print '<td align="right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td colspan="4"> </td>' ;
print '</tr>' ;
$var =! $var ;
print '<tr ' . $bc [ $var ] . '>' ;
print '<td colspan="3">' ;
$ajaxoptions = array (
2013-11-28 15:54:12 +01:00
'update' => array ( 'qty_predef' => 'qty' , 'remise_percent_predef' => 'discount' ), // html id tag will be edited with which ajax json response key
'option_disabled' => 'addPredefinedProductButton' , // html id to disable once select is done
'error' => $langs -> trans ( " NoPriceDefinedForThisSupplier " ) // translation of an error saved into var 'error'
2012-12-01 15:45:05 +01:00
);
2013-11-17 23:25:25 +01:00
$form -> select_produits_fournisseurs ( $object -> fourn_id , GETPOST ( 'idprodfournprice' ), 'idprodfournprice' , '' , '' , $ajaxoptions );
2012-12-01 15:45:05 +01:00
if ( empty ( $conf -> global -> PRODUIT_USE_SEARCH_TO_SELECT )) print '<br>' ;
if ( is_object ( $hookmanager ))
{
$parameters = array ( 'htmlname' => 'idprodfournprice' );
$reshook = $hookmanager -> executeHooks ( 'formCreateProductSupplierOptions' , $parameters , $object , $action );
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
$nbrows = ROWS_2 ;
if ( ! empty ( $conf -> global -> MAIN_INPUT_DESC_HEIGHT )) $nbrows = $conf -> global -> MAIN_INPUT_DESC_HEIGHT ;
$doleditor = new DolEditor ( 'np_desc' , GETPOST ( 'np_desc' ), '' , 100 , 'dolibarr_details' , '' , false , true , $conf -> global -> FCKEDITOR_ENABLE_DETAILS , $nbrows , 70 );
$doleditor -> Create ();
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '</td>' ;
2013-11-17 23:25:25 +01:00
print '<td align="right"><input type="text" size="2" id="qty_predef" name="qty_predef" value="' . ( GETPOST ( 'qty_predef' ) ? GETPOST ( 'qty_predef' ) : '1' ) . '"></td>' ;
print '<td align="right" class="nowrap"><input type="text" size="1" id="remise_percent_predef" name="remise_percent_predef" value="' . ( GETPOST ( 'remise_percent_predef' ) ? GETPOST ( 'remise_percent_predef' ) : $object -> thirdparty -> remise_percent ) . '"><span class="hideonsmartphone">%</span></td>' ;
print '<td align="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="' . $langs -> trans ( 'Add' ) . '" name="addline_predefined"></td>' ;
2012-12-01 15:45:05 +01:00
print '</tr>' ;
}
}
print '</table>' ;
2013-11-17 23:25:25 +01:00
print '</form>' ;
dol_fiche_end ();
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( $action != 'presend' )
{
/**
* Boutons actions
*/
2013-11-17 23:25:25 +01:00
if ( $user -> societe_id == 0 && $action != 'edit_line' && $action != 'delete' )
2012-12-01 15:45:05 +01:00
{
2013-04-16 01:13:20 +02:00
print '<div class="tabsAction">' ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Validate
if ( $object -> statut == 0 && $num > 0 )
{
if ( $user -> rights -> fournisseur -> commande -> valider )
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid"' ;
print '>' . $langs -> trans ( 'Validate' ) . '</a>' ;
}
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Modify
if ( $object -> statut == 1 )
{
if ( $user -> rights -> fournisseur -> commande -> commander )
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " Modify " ) . '</a>' ;
}
}
2010-12-01 22:16:28 +01:00
2012-12-01 15:45:05 +01:00
// Approve
if ( $object -> statut == 1 )
{
if ( $user -> rights -> fournisseur -> commande -> approuver )
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=approve">' . $langs -> trans ( " ApproveOrder " ) . '</a>' ;
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=refuse">' . $langs -> trans ( " RefuseOrder " ) . '</a>' ;
}
else
{
print '<a class="butActionRefused" href="#">' . $langs -> trans ( " ApproveOrder " ) . '</a>' ;
print '<a class="butActionRefused" href="#">' . $langs -> trans ( " RefuseOrder " ) . '</a>' ;
}
}
2010-12-01 23:43:22 +01:00
2012-12-01 15:45:05 +01:00
// Send
if ( in_array ( $object -> statut , array ( 2 , 3 , 4 , 5 )))
{
if ( $user -> rights -> fournisseur -> commande -> commander )
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=presend&mode=init">' . $langs -> trans ( 'SendByMail' ) . '</a>' ;
}
}
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
// Reopen
if ( in_array ( $object -> statut , array ( 5 , 6 , 7 , 9 )))
{
if ( $user -> rights -> fournisseur -> commande -> commander )
{
print '<a class="butAction" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=reopen">' . $langs -> trans ( " ReOpen " ) . '</a>' ;
}
}
2010-12-01 22:16:28 +01:00
2012-12-01 15:45:05 +01:00
// Create bill
if ( ! empty ( $conf -> fournisseur -> enabled ) && $object -> statut >= 2 ) // 2 means accepted
{
if ( $user -> rights -> fournisseur -> facture -> creer )
{
print '<a class="butAction" href="' . DOL_URL_ROOT . '/fourn/facture/fiche.php?action=create&origin=' . $object -> element . '&originid=' . $object -> id . '&socid=' . $object -> socid . '">' . $langs -> trans ( " CreateBill " ) . '</a>' ;
}
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
//if ($user->rights->fournisseur->commande->creer && $object->statut > 2)
//{
// print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled">'.$langs->trans("ClassifyBilled").'</a>';
//}
}
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
// Cancel
if ( $object -> statut == 2 )
{
if ( $user -> rights -> fournisseur -> commande -> commander )
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=cancel">' . $langs -> trans ( " CancelOrder " ) . '</a>' ;
}
}
2009-02-02 23:11:10 +01:00
2012-12-01 15:45:05 +01:00
// Clone
if ( $user -> rights -> fournisseur -> commande -> creer )
{
print '<a class="butAction" href="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '&socid=' . $object -> socid . '&action=clone&object=order">' . $langs -> trans ( " ToClone " ) . '</a>' ;
}
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
// Delete
if ( $user -> rights -> fournisseur -> commande -> supprimer )
{
print '<a class="butActionDelete" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
}
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
print " </div> " ;
}
2013-04-21 14:24:19 +02:00
print " <br> " ;
2013-04-16 01:23:33 +02:00
2010-12-13 14:16:02 +01:00
2013-04-21 14:24:19 +02:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
2013-04-16 01:13:20 +02:00
//print '<table width="100%"><tr><td width="50%" valign="top">';
//print '<a name="builddoc"></a>'; // ancre
2010-12-13 14:16:02 +01:00
2012-12-01 15:45:05 +01:00
/*
* Documents generes
*/
$comfournref = dol_sanitizeFileName ( $object -> 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= " . $object -> id ;
$genallowed = $user -> rights -> fournisseur -> commande -> creer ;
$delallowed = $user -> rights -> fournisseur -> commande -> supprimer ;
2010-12-13 14:16:02 +01:00
2012-12-01 15:45:05 +01:00
print $formfile -> showdocuments ( 'commande_fournisseur' , $comfournref , $filedir , $urlsource , $genallowed , $delallowed , $object -> modelpdf , 1 , 0 , 0 , 0 , 0 , '' , '' , '' , $object -> thirdparty -> default_lang );
$somethingshown = $formfile -> numoffiles ;
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
/*
* Linked object block
*/
$somethingshown = $object -> showLinkedObjectBlock ();
2013-11-17 23:25:25 +01:00
2013-08-09 13:48:44 +02:00
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
2013-11-17 23:25:25 +01:00
2013-08-09 13:48:44 +02:00
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'order_supplier' , $socid );
print '</div></div></div>' ;
2011-10-14 16:44:22 +02:00
2013-04-16 01:13:20 +02:00
//print '</td><td valign="top" width="50%">';
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
2008-07-09 01:02:16 +02:00
2012-12-01 15:45:05 +01:00
if ( $user -> rights -> fournisseur -> commande -> commander && $object -> statut == 2 )
{
/*
* Commander ( action = commande )
*/
print '<br>' ;
print '<form name="commande" action="fiche.php?id=' . $object -> id . '&action=commande" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="commande">' ;
print '<table class="border" width="100%">' ;
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " ToOrder " ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " OrderDate " ) . '</td><td>' ;
$date_com = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'remonth' ), GETPOST ( 'reday' ), GETPOST ( 'reyear' ));
print $form -> select_date ( $date_com , '' , '' , '' , '' , " commande " );
print '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " OrderMode " ) . '</td><td>' ;
$formorder -> select_methodes_commande ( GETPOST ( 'methodecommande' ), " methodecommande " , 1 );
print '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " Comment " ) . '</td><td><input size="40" type="text" name="comment" value="' . GETPOST ( 'comment' ) . '"></td></tr>' ;
print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="' . $langs -> trans ( " ToOrder " ) . '"></td></tr>' ;
print '</table>' ;
print '</form>' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
if ( $user -> rights -> fournisseur -> commande -> receptionner && ( $object -> statut == 3 || $object -> statut == 4 ))
{
/*
* Receptionner ( action = livraison )
*/
print '<br>' ;
print '<form action="fiche.php?id=' . $object -> id . '" method="post">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="livraison">' ;
print '<table class="border" width="100%">' ;
print '<tr class="liste_titre"><td colspan="2">' . $langs -> trans ( " Receive " ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " DeliveryDate " ) . '</td><td>' ;
print $form -> select_date ( '' , '' , '' , '' , '' , " commande " );
print " </td></tr> \n " ;
print " <tr><td> " . $langs -> trans ( " Delivery " ) . " </td><td> \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 $form -> selectarray ( " type " , $liv );
print '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( " Comment " ) . '</td><td><input size="40" type="text" name="comment"></td></tr>' ;
print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="' . $langs -> trans ( " Receive " ) . '"></td></tr>' ;
print " </table> \n " ;
print " </form> \n " ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// List of actions on element
/* Hidden because " available into " Log " tab
print '<br>' ;
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , 'order_supplier' , $socid );
*/
2011-10-14 16:44:22 +02:00
2013-04-16 01:13:20 +02:00
print '</div></div></div>' ;
//print '</td></tr></table>';
2012-12-01 15:45:05 +01:00
}
2012-03-16 00:34:41 +01:00
2012-12-01 15:45:05 +01:00
/*
* Action presend
*/
if ( $action == 'presend' )
{
$ref = dol_sanitizeFileName ( $object -> ref );
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2013-03-30 13:54:46 +01:00
$fileparams = dol_most_recent_file ( $conf -> fournisseur -> commande -> dir_output . '/' . $ref , preg_quote ( $ref , '/' ));
2012-12-01 15:45:05 +01:00
$file = $fileparams [ 'fullname' ];
2012-03-16 00:34:41 +01:00
2012-12-01 15:45:05 +01:00
// 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 );
}
2011-10-14 16:44:22 +02:00
2013-01-26 10:35:30 +01:00
$result = supplier_order_pdf_create ( $db , $object , GETPOST ( 'model' ) ? GETPOST ( 'model' ) : $object -> modelpdf , $outputlangs , $hidedetails , $hidedesc , $hideref );
2012-12-01 15:45:05 +01:00
if ( $result <= 0 )
{
dol_print_error ( $db , $result );
exit ;
}
2013-03-30 13:54:46 +01:00
$fileparams = dol_most_recent_file ( $conf -> fournisseur -> commande -> dir_output . '/' . $ref , preg_quote ( $ref , '/' ));
2012-12-01 15:45:05 +01:00
$file = $fileparams [ 'fullname' ];
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '<br>' ;
print_titre ( $langs -> trans ( 'SendOrderByMail' ));
// 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 ;
2013-02-12 17:08:21 +01:00
$liste = array ();
foreach ( $object -> thirdparty -> thirdparty_and_contact_email_array ( 1 ) as $key => $value ) $liste [ $key ] = $value ;
2013-09-05 18:06:51 +02:00
$formmail -> withto = GETPOST ( " sendto " ) ? GETPOST ( " sendto " ) : $liste ;
2013-02-12 17:08:21 +01:00
$formmail -> withtocc = $liste ;
2012-12-01 15:45:05 +01:00
$formmail -> withtoccc = ( ! empty ( $conf -> global -> MAIN_EMAIL_USECCC ) ? $conf -> global -> MAIN_EMAIL_USECCC : false );
$formmail -> withtopic = $langs -> trans ( 'SendOrderRef' , '__ORDERREF__' );
$formmail -> withfile = 2 ;
$formmail -> withbody = 1 ;
$formmail -> withdeliveryreceipt = 1 ;
$formmail -> withcancel = 1 ;
// Tableau des substitutions
$formmail -> substit [ '__ORDERREF__' ] = $object -> ref ;
$formmail -> substit [ '__SIGNATURE__' ] = $user -> signature ;
$formmail -> substit [ '__PERSONALIZED__' ] = '' ;
2013-03-23 14:39:23 +01:00
$formmail -> substit [ '__CONTACTCIVNAME__' ] = '' ;
2013-03-24 21:06:45 +01:00
2013-03-23 14:39:23 +01:00
//Find the good contact adress
$custcontact = '' ;
$contactarr = array ();
$contactarr = $object -> liste_contact ( - 1 , 'external' );
2013-03-24 21:06:45 +01:00
2013-03-23 14:39:23 +01:00
if ( is_array ( $contactarr ) && count ( $contactarr ) > 0 ) {
foreach ( $contactarr as $contact ) {
if ( $contact [ 'libelle' ] == $langs -> trans ( 'TypeContact_order_supplier_external_BILLING' )) {
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
$contactstatic = new Contact ( $db );
$contactstatic -> fetch ( $contact [ 'id' ]);
$custcontact = $contactstatic -> getFullName ( $langs , 1 );
}
}
2013-03-24 21:06:45 +01:00
2013-03-23 14:39:23 +01:00
if ( ! empty ( $custcontact )) {
$formmail -> substit [ '__CONTACTCIVNAME__' ] = $custcontact ;
}
}
2013-03-24 21:06:45 +01:00
2012-12-01 15:45:05 +01:00
// Tableau des parametres complementaires
$formmail -> param [ 'action' ] = 'send' ;
$formmail -> param [ 'models' ] = 'order_supplier_send' ;
$formmail -> param [ 'orderid' ] = $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 ));
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
// Show form
$formmail -> show_form ();
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '<br>' ;
}
2011-10-14 16:44:22 +02:00
2012-12-01 15:45:05 +01:00
print '</td></tr></table>' ;
2006-12-05 01:47:40 +01:00
}
2004-11-29 17:48:53 +01:00
2012-03-15 09:19:38 +01:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-04-13 14:02:53 +02:00
2012-03-15 09:19:38 +01:00
$db -> close ();
2012-05-08 21:55:52 +02:00
?>