From 6ac08c3bee4ca8cac8a2be589a0fd63dc95e3bb9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 29 May 2017 10:32:17 +0200 Subject: [PATCH 001/148] Fix : Product supplier price is related to supplier's currency --- htdocs/fourn/class/fournisseur.commande.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 245947932a3..df48e35c01d 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1408,7 +1408,8 @@ class CommandeFournisseur extends CommonOrder $result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->fk_soc); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref/$this->fk_soc if ($result > 0) { - $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice + $pu = 0; // Unit price supplier price set by get_buyprice + $pu_ht_devise = $prod->fourn_pu; // With multicurrency, supplier price is related to its currency, $pu will be calculated (= $pu_ht_devise if exchange rate is 1) $ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice } if ($result == 0) // If result == 0, we failed to found the supplier reference price From f876833b9a8eed8bbd1cb2789a91ca83a1df7882 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 18 Jul 2017 10:31:35 +0200 Subject: [PATCH 002/148] Fix : search on rowid don't work with pgsql and natural search --- htdocs/adherents/list.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 4eda43dcca5..1334bc2ba7e 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -83,7 +83,6 @@ $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search // List of fields to search into when doing a "search in all" $fieldstosearchall = array( - 'd.rowid'=>'Ref', 'd.login'=>'Login', 'd.lastname'=>'Lastname', 'd.firstname'=>'Firstname', From 6fcfe895659fc7df1c0f16b3eef4ee22f90b16d1 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 26 Sep 2017 13:02:29 +0200 Subject: [PATCH 003/148] NEW : lettrage in accountancy --- .../bookkeeping/thirdparty_lettrage.php | 453 ++++++++-------- .../thirdparty_lettrage_supplier.php | 492 ++++++++--------- htdocs/accountancy/class/lettering.class.php | 504 ++++++++++-------- htdocs/accountancy/journal/bankjournal.php | 2 + htdocs/core/lib/company.lib.php | 18 + 5 files changed, 759 insertions(+), 710 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php index 5f621a55186..782a7de7aa4 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage.php @@ -21,11 +21,10 @@ */ /** - * \file accounting/bookkeeping/thirdparty_lettrage.php + * \file accounting/bookkeeping/thirdparty_lettrage.php * \ingroup Advanced accountancy - * \brief Onglet de gestion de parametrages des ventilations + * \brief Onglet de gestion de parametrages des ventilations */ - require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; @@ -34,296 +33,286 @@ require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; -$action=GETPOST('action','aZ09'); -$massaction=GETPOST('massaction','alpha'); -$show_files=GETPOST('show_files','int'); -$confirm=GETPOST('confirm','alpha'); +$action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); +$show_files = GETPOST('show_files', 'int'); +$confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if (empty($page) || $page == - 1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if ($sortorder == "") $sortorder = "ASC"; -if ($sortfield == "") $sortfield = "bk.rowid"; +if ($sortorder == "") + $sortorder = "DESC"; +if ($sortfield == "") + $sortfield = "bk.doc_date"; -$search_year = GETPOST ( "search_year" ); +$search_year = GETPOST("search_year", 'int'); +$search_doc_type = GETPOST("search_doc_type", 'alpha'); +$search_doc_ref = GETPOST("search_doc_ref", 'alpha'); + +$lettering = GETPOST('lettering'); +if (! empty($lettering)) { + $action = $lettering; +} +$toselect = GETPOST('toselect', 'array'); + +// Did we click on purge search criteria ? +// All tests are required to be compatible with all browsers +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { + $search_year = ''; + $search_doc_type = ''; + $search_doc_ref = ''; +} // Security check -$socid = GETPOST("socid",'int'); +$socid = GETPOST("socid", 'int'); // if ($user->societe_id) $socid=$user->societe_id; $object = new Societe($db); $object->id = $socid; -$object->fetch($socid); - +$result = $object->fetch($socid); +if ($result < 0) { + setEventMessage($object->error, 'errors'); +} $form = new Form($db); $BookKeeping = new lettering($db); $formaccounting = new FormAccounting($db); - /* * Action */ if ($action == 'lettering') { - $result = $BookKeeping->updatelettrage($_POST['ids']); - -// var_dump($result); - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; + $result = $BookKeeping->updateLettrage($toselect); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; } } if ($action == 'autolettrage') { - $result = $BookKeeping->LettrageTiers($socid); - - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; - - } + $result = $BookKeeping->lettrageTiers($socid); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; + } } +llxHeader('', 'Compta - Grand Livre'); -llxHeader ( '', 'Compta - Grand Livre' ); +/* + * Affichage onglets + */ +$head = societe_prepare_head($object); +dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); - /* - * Affichage onglets - */ - $head = societe_prepare_head($object); +dol_fiche_head($head, 'accounting', $langs->trans("ThirdParty"), 0, 'company'); - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); +print ''; +print ''; - dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); +if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field +{ + print ''; +} +print ''; +print ''; +print ''; +$langs->load('compta'); +print ''; +print ''; +print ''; +// Address +print ''; - print '
' . $langs->trans("ThirdPartyName") . ''; +$object->next_prev_filter = "te.fournisseur = 1"; +print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', ''); +print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans("CustomerCode") . ''; +print $object->code_client; +if ($object->check_codeclient() != 0) + print ' (' . $langs->trans("WrongCustomerCode") . ')'; +print '
'; +print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); +print ''; +print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); +print '
' . $langs->trans("Address") . ''; +dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); +print '
'; - print ''; +// Zip / Town +print ''; +print ''; - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } +// Country +print ''; +print '
'.$langs->trans("ThirdPartyName").''; - $object->next_prev_filter="te.fournisseur = 1"; - print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); - print '
' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
' . $langs->trans("Country") . ''; +// $img=picto_from_langcode($object->country_code); +$img = ''; +if ($object->isInEEC()) + print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0); +else + print ($img ? $img . ' ' : '') . $object->country; +print '
'; - print ''; - print ''.$langs->trans("CustomerCode"). ''; - print $object->code_client; - if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; - print ''; - print ''; +$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, "; +$sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, "; +$sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code "; +$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; +$sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . "' )"; - $langs->load('compta'); - print ''; - print ''; - print $form->editfieldkey("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); - print ''; - print $form->editfieldval("CustomerAccountancyCode",'customeraccountancycode',$object->code_compta,$object,$user->rights->societe->creer); - print ''; - print ''; +if (dol_strlen($search_year)) { + $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year); + $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year); + $sql .= " AND ( bk.doc_date BETWEEN '" . $db->idate($date_start) . "' AND '" . $db->idate($date_end) . "' )"; +} +$sql .= $db->order($sortfield, $sortorder); - // Address - print ''.$langs->trans("Address").''; - dol_print_address($object->address,'gmap','thirdparty',$object->id); - print ''; +$debit = 0; +$credit = 0; +$solde = 0; +// Count total nb of records and calc total sum +$nbtotalofrecords = ''; +$resql = $db->query($sql); +if (! $resql) { + dol_print_error($db); + exit(); +} +$nbtotalofrecords = $db->num_rows($resql); - // Zip / Town - print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.''; +while ( $obj = $db->fetch_object($resql) ) { + $debit += $obj->debit; + $credit += $obj->credit; + + $solde += ($obj->credit - $obj->debit); +} + +$sql .= $db->plimit($limit + 1, $offset); + +dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG); +$resql = $db->query($sql); +if (! $resql) { + dol_print_error($db); + exit(); +} + +$num = $db->num_rows($resql); + +dol_syslog("/accountancy/bookkeeping/thirdparty_lettrage.php", LOG_DEBUG); +if ($resql) { + $i = 0; + + print '
'; + print ''; + + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit); + + print ""; + print ''; + print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal", "", $param, "", $sortfield, $sortorder); + print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder); + print ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print ''; - // Country - print ''; + $var = false; + $solde = 0; + $tmp = ''; + while ( $obj = $db->fetch_object($resql) ) { - print '
 '; + $searchpicto = $form->showFilterButtons(); + print $searchpicto; + print '
'.$langs->trans("Country").''; - //$img=picto_from_langcode($object->country_code); - $img=''; - if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); - else print ($img?$img.' ':'').$object->country; - print '
'; + if ($tmp != $obj->lettering_code || empty($tmp)) + $tmp = $obj->lettering_code; + if ($tmp != $obj->lettering_code || empty($obj->lettering_code)) + $var = ! $var; + $solde += ($obj->credit - $obj->debit); + print ""; + if (empty($obj->lettering_code)) { + print ''; + print img_edit(); + print ' ' . $obj->doc_type . '' . "\n"; + } else + print '' . $obj->doc_type . '' . "\n"; - $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE (bk.code_tiers = '" . $object->code_compta . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_CUSTOMER. "' )" ; + print '' . dol_print_date($db->jdate($obj->doc_date), 'day') . ''; + print '' . $obj->doc_ref . ''; + print '' . $obj->label_compte . ''; + print '' . price($obj->debit) . ''; + print '' . price($obj->credit) . ''; + print '' . price($obj->montant) . ''; + print '' . $obj->sens . ''; + print '' . $obj->code_journal . ''; + print '' . round($solde, 2) . ''; + if (empty($obj->lettering_code)) { + print ''; + } else + print '' . $obj->lettering_code . ''; - - if (dol_strlen ( $search_year )) { - $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; - } - - - $sql .= " ORDER BY bk.lettering_code ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); - -// echo $sql; -// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); - $resql = $db->query ( $sql ); - if ($resql) { - $num = $db->num_rows ( $resql ); - $i = 0; - - - print ''; - print ''; - print ''; - - print ""; - print ''; - print ''; - print_liste_field_titre("Doctype", "liste.php", "bk.doc_type" ); - print_liste_field_titre("Docdate", "liste.php", "bk.doc_date" ); - print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" ); -// print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" ); -// print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" ); - print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" ); - print_liste_field_titre("Debit", "liste.php", "bk.debit" ); - print_liste_field_titre("Credit", "liste.php", "bk.credit" ); -// print_liste_field_titre("Amount", "liste.php", "bk.montant" ); -// print_liste_field_titre("Sens", "liste.php", "bk.sens" ); - print_liste_field_titre("Codejournal", "liste.php", "bk.code_journal" ); - print ''; - print ''; print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = false; - - $debit = 0; - $credit = 0; - $solde = 0; - $tmp = ''; - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - - if($tmp !=$obj->lettering_code || empty($tmp) ) - $tmp =$obj->lettering_code; - - if($tmp !=$obj->lettering_code || empty($obj->lettering_code)) - $var = ! $var; - - - $debit+= $obj->debit; - $credit+= $obj->credit; - - $solde+=($obj->credit-$obj->debit); - print ""; - - print ''; - if(empty($obj->lettering_code)){ - print '' . "\n"; - } - else - print '' . "\n"; - - - - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - - if(empty($obj->lettering_code)){ - print ''; - } - else - print ''; - - print "\n"; - - $i ++; - - - - - } - - print ''; - - print '' . "\n"; - print ''; - // print ''; - // print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print ""; - print '' . "\n"; - // print ''; - // print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print "
     '; - print ''; - print '   
' . $obj->rowid . ''; - print img_edit (); - print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering_code . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; - - print ''; - print 'auto lettering'; - print ""; - $db->free($resql); - } else { - dol_print_error($db); } + print ''; + + print 'Mouvement totaux' . "\n"; + print '' . price($debit) . ''; + print '' . price($credit) . ''; + print ''; + print "\n"; + + print ""; + print 'Solde Comptable' . "\n"; + print '' . price($credit - $debit) . ''; + print ''; + print "\n"; + + print ""; + + print ''; + print '' . $langs->trans('AccountancyAutoLettering') . ''; + print ""; + $db->free($resql); +} else { + dol_print_error($db); +} // End of page llxFooter(); diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php index 623e54f71fb..5ac224673aa 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettrage_supplier.php @@ -21,9 +21,9 @@ */ /** - * \file accounting/bookkeeping/thirdparty_lettrage.php + * \file accounting/bookkeeping/thirdparty_lettrage.php * \ingroup Advanced accountancy - * \brief Tab to setup lettering + * \brief Tab to setup lettering */ // Dolibarr environment @@ -35,300 +35,304 @@ require_once DOL_DOCUMENT_ROOT . '/accountancy/class/lettering.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; - -$action=GETPOST('action','aZ09'); -$massaction=GETPOST('massaction','alpha'); -$show_files=GETPOST('show_files','int'); -$confirm=GETPOST('confirm','alpha'); +$action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); +$show_files = GETPOST('show_files', 'int'); +$confirm = GETPOST('confirm', 'alpha'); $toselect = GETPOST('toselect', 'array'); -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if (empty($page) || $page == - 1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if ($sortorder == "") $sortorder = "ASC"; -if ($sortfield == "") $sortfield = "bk.rowid"; +if ($sortorder == "") + $sortorder = "DESC"; +if ($sortfield == "") + $sortfield = "bk.doc_date"; -$search_year = GETPOST ( "search_year" ); +$search_year = GETPOST("search_year",'int'); +$search_doc_type = GETPOST("search_doc_type",'alpha'); +$search_doc_ref = GETPOST("search_doc_ref",'alpha'); + +$lettering = GETPOST('lettering'); +if (!empty($lettering)) { + $action=$lettering; +} +$toselect = GETPOST('toselect','array'); + +// Did we click on purge search criteria ? +// All tests are required to be compatible with all browsers +if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) +{ + $search_year=''; + $search_doc_type=''; + $search_doc_ref=''; +} // Security check -$socid = GETPOST("socid",'int'); +$socid = GETPOST("socid", 'int'); // if ($user->societe_id) $socid=$user->societe_id; $object = new Societe($db); $object->id = $socid; -$object->fetch($socid); +$result = $object->fetch($socid); +if ($result<0) { + setEventMessage($object->error,'errors'); +} $form = new Form($db); $BookKeeping = new lettering($db); $formaccounting = new FormAccounting($db); - /* * Action */ if ($action == 'lettering') { - $result = $BookKeeping->updatelettrage($_POST['ids']); - -// var_dump($result); - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; + $result = $BookKeeping->updateLettrage($toselect); + // var_dump($result); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; } } if ($action == 'autolettrage') { - $result = $BookKeeping->LettrageTiers($socid); - - if( $result < 0 ){ - setEventMessages('', $BookKeeping->errors, 'errors' ); - $error++; - - } + $result = $BookKeeping->lettrageTiers($socid); + if ($result < 0) { + setEventMessages('', $BookKeeping->errors, 'errors'); + $error ++; + } } +$title = 'AccountancyLettrage'; -llxHeader ( '', 'Compta - Grand Livre' ); +llxHeader('', $title); - /* - * Affichage onglets - */ - $head = societe_prepare_head($object); +$param=''; +if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; +if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; +if (!empty($search_year)) $param.='&search_year='.$search_year; +if (!empty($socid)) $param.='&socid='.$socid; +if (!empty($search_doc_type)) $param.='&search_doc_type='.$search_doc_type; +if (!empty($search_doc_ref)) $param.='&search_doc_ref='.$search_doc_ref; - dol_htmloutput_mesg(is_numeric($error)?'':$error, $errors, 'error'); - - dol_fiche_head($head, 'TabAccounting', $langs->trans("ThirdParty"),0,'company'); - - - - - print ''; - print ''; - - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { - print ''; - } - - - print ''; - print ''; - print ''; - - $langs->load('compta'); - print ''; - print ''; - print ''; - - - // Address - print ''; - - // Zip / Town - print ''; - print ''; - - // Country - print ''; - - print '
'.$langs->trans("ThirdPartyName").''; - $object->next_prev_filter="te.fournisseur = 1"; - print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); - print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans("SupplierCode"). ''; - print $object->code_fournisseur; - if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; - print '
'; - print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); - print ''; - print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); - print '
'.$langs->trans("Address").''; - dol_print_address($object->address,'gmap','thirdparty',$object->id); - print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'
'.$langs->trans("Country").''; - //$img=picto_from_langcode($object->country_code); - $img=''; - if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); - else print ($img?$img.' ':'').$object->country; - print '
'; - -// print_r($soc); -// exit; -// [code_compta] => 411DOUA -// [code_compta_fournisseur] => 401SUPPCODE /* - * Mode Liste - * - * - * + * Affichage onglets */ +$head = societe_prepare_head($object); - $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE (bk.code_tiers = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" .$conf->global->ACCOUNTING_ACCOUNT_SUPPLIER. "' )" ; +dol_htmloutput_mesg(is_numeric($error) ? '' : $error, $errors, 'error'); +dol_fiche_head($head, 'accounting_supplier', $langs->trans("ThirdParty"), 0, 'company'); +print ''; +print ''; - if (dol_strlen ( $search_year )) { - $sql .= " AND ( bk.doc_date BETWEEN '" . $search_year . "-0-0' AND '" . ($search_year+1). "-0-0' )"; - } +if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field +{ + print ''; +} +print ''; +print ''; +print ''; - $sql .= " ORDER BY bk.lettering ASC, bk.doc_date ASC" ;//. $db->plimit ( $conf->liste_limit + 1, $offset ); +$langs->load('compta'); +print ''; +print ''; +print ''; -// echo $sql; -// dol_syslog ( "bookkeping:liste:create sql=" . $sql, LOG_DEBUG ); - $resql = $db->query ( $sql ); - if ($resql) { - $num = $db->num_rows ( $resql ); - $i = 0; +// Address +print ''; +// Zip / Town +print ''; +print ''; - print ''; - print ''; - print ''; +// Country +print ''; + +print '
' . $langs->trans("ThirdPartyName") . ''; +$object->next_prev_filter = "te.fournisseur = 1"; +print $form->showrefnav($object, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom', '', ''); +print '
' . $langs->trans('Prefix') . '' . $object->prefix_comm . '
' . $langs->trans("SupplierCode") . ''; +print $object->code_fournisseur; +if ($object->check_codefournisseur() != 0) + print ' (' . $langs->trans("WrongSupplierCode") . ')'; +print '
'; +print $form->editfieldkey("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer); +print ''; +print $form->editfieldval("SupplierAccountancyCode", 'supplieraccountancycode', $object->code_compta_fournisseur, $object, $user->rights->societe->creer); +print '
' . $langs->trans("Address") . ''; +dol_print_address($object->address, 'gmap', 'thirdparty', $object->id); +print '
' . $langs->trans("Zip") . ' / ' . $langs->trans("Town") . '' . $object->zip . (($object->zip && $object->town) ? ' / ' : '') . $object->town . '
' . $langs->trans("Country") . ''; +// $img=picto_from_langcode($object->country_code); +$img = ''; +if ($object->isInEEC()) + print $form->textwithpicto(($img ? $img . ' ' : '') . $object->country, $langs->trans("CountryIsInEEC"), 1, 0); +else + print ($img ? $img . ' ' : '') . $object->country; +print '
'; + +$sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, "; +$sql .= " bk.thirdparty_code, bk.numero_compte , bk.label_compte, bk.debit, "; +$sql .= " bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.lettering_code "; +$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; +$sql .= " WHERE (bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' AND bk.numero_compte = '" . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . "' )"; + +if (dol_strlen($search_year)) { + $date_start = dol_mktime(0, 0, 0, 1, 1, $search_year); + $date_end = dol_mktime(23, 59, 59, 12, 31, $search_year); + $sql .= " AND ( bk.doc_date BETWEEN '".$db->idate($date_start)."' AND '".$db->idate($date_end)."' )"; +} + +$sql.= $db->order($sortfield,$sortorder); + +$debit = 0; +$credit = 0; +$solde = 0; +// Count total nb of records and calc total sum +$nbtotalofrecords = ''; +$resql = $db->query($sql); +if (! $resql) +{ + dol_print_error($db); + exit; +} +$nbtotalofrecords = $db->num_rows($resql); + +while ($obj = $db->fetch_object($resql)) { + $debit += $obj->debit; + $credit += $obj->credit; + + $solde += ($obj->credit - $obj->debit); +} + +$sql.= $db->plimit($limit+1, $offset); + +dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG ); +$resql = $db->query($sql); +if (! $resql) +{ + dol_print_error($db); + exit; +} + +$num = $db->num_rows($resql); + +dol_syslog ( "/accountancy/bookkeeping/thirdparty_lettrage_supplier.php", LOG_DEBUG ); +$resql = $db->query($sql); +if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + print ''; + print ''; + + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit); + + print ""; + print ''; + print_liste_field_titre("Doctype", $_SERVER["PHP_SELF"], "bk.doc_type","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Docdate", $_SERVER["PHP_SELF"], "bk.doc_date","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Docref", $_SERVER["PHP_SELF"], "bk.doc_ref","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Labelcompte", $_SERVER["PHP_SELF"], "bk.label_compte","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Debit", $_SERVER["PHP_SELF"], "bk.debit","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Credit", $_SERVER["PHP_SELF"], "bk.credit","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bk.montant","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Sens", $_SERVER["PHP_SELF"], "bk.sens","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Codejournal", $_SERVER["PHP_SELF"], "bk.code_journal","",$param,"",$sortfield,$sortorder); + print_liste_field_titre("Solde", $_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); + print ''; + print "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $var = false; + $solde = 0; + $tmp = ''; + while ($obj = $db->fetch_object($resql)) { + + if ($tmp != $obj->lettering_code || empty($tmp)) + $tmp = $obj->lettering_code; + + if ($tmp != $obj->lettering_code || empty($obj->lettering_code)) + $var = ! $var; + + $solde += ($obj->credit - $obj->debit); + + print ""; + + if (empty($obj->lettering_code)) { + print '' . "\n"; + } else + print '' . "\n"; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + if (empty($obj->lettering_code)) { + print ''; + } else + print ''; - print "
 '; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
'; + print img_edit(); + print ' ' . $obj->doc_type . '' . $obj->doc_type . '' . dol_print_date($db->jdate($obj->doc_date), 'day') . '' . $obj->doc_ref . '' . $obj->label_compte . '' . price($obj->debit) . '' . price($obj->credit) . '' . price($obj->montant) . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering_code . '
"; - print ''; - print ''; - print_liste_field_titre("Doctype", "liste.php", "bk.doc_type" ); - print_liste_field_titre("Docdate", "liste.php", "bk.doc_date" ); - print_liste_field_titre("Docref", "liste.php", "bk.doc_ref" ); -// print_liste_field_titre("Numerocompte", "liste.php", "bk.numero_compte" ); -// print_liste_field_titre("Code_tiers", "liste.php", "bk.code_tiers" ); - print_liste_field_titre("Labelcompte", "liste.php", "bk_label_compte" ); - print_liste_field_titre("Debit", "liste.php", "bk.debit" ); - print_liste_field_titre("Credit", "liste.php", "bk.credit" ); - print_liste_field_titre("Amount", "liste.php", "bk.montant" ); - print_liste_field_titre("Sens", "liste.php", "bk.sens" ); - print_liste_field_titre("Codejournal", "liste.php", "bk.code_journal" ); - print ''; - print ''; print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $var = false; - - $debit = 0; - $credit = 0; - $solde = 0; - $tmp = ''; - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - - if($tmp !=$obj->lettering || empty($tmp) ) - $tmp =$obj->lettering; - - if($tmp !=$obj->lettering || empty($obj->lettering)) - $var = ! $var; - - - $debit+= $obj->debit; - $credit+= $obj->credit; - - $solde+=($obj->credit-$obj->debit); - print ""; - - print ''; - if(empty($obj->lettering)){ - print '' . "\n"; - } - else - print '' . "\n"; - - - - print ''; - print ''; -// print ''; -// print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - if(empty($obj->lettering)){ - print ''; - } - else - print ''; - - print "\n"; - - $i ++; - } - - print ''; - - print '' . "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print ""; - print '' . "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - print "
     '; - print ''; - print '   
' . $obj->rowid . ''; - print img_edit (); - print ' ' . $obj->doc_type . ''.$obj->doc_type . '' . dol_print_date ( $db->jdate ( $obj->doc_date ), 'day' ) . '' . $obj->doc_ref . '' . $obj->numero_compte . '' . $obj->code_tiers . '' . $obj->label_compte . '' . $obj->debit . '' . $obj->credit . '' . $obj->montant . '' . $obj->sens . '' . $obj->code_journal . '' . round($solde, 2) . '' . $obj->lettering . '
Mouvement totaux' . $debit . '' . $credit . ' 
Solde Comptable' . ($credit-$debit) . ' 
"; - - print ''; - print 'auto lettering'; - print ""; - $db->free ( $resql ); - } else { - dol_print_error ( $db ); } + print ''; + + print 'Mouvement totaux' . "\n"; + print '' . price($debit) . ''; + print '' . price($credit) . ''; + print ''; + print "\n"; + + print ""; + print 'Solde Comptable' . "\n"; + print '' . price($credit - $debit) . ''; + print ''; + print "\n"; + + print ""; + + print ''; + print ''.$langs->trans('AccountancyAutoLettering').''; + print ""; + $db->free($resql); +} else { + dol_print_error($db); +} // End of page llxFooter(); diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index 97721669f91..e94c33d69e5 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -18,313 +18,349 @@ */ /** - * \file accountancy/class/bookkeeping.class.php - * \ingroup Advanced accountancy - * \brief File of class for lettering + * \file accountancy/class/bookkeeping.class.php + * \ingroup Advanced accountancy + * \brief File of class for lettering */ - -include_once DOL_DOCUMENT_ROOT."/accountancy/class/bookkeeping.class.php"; -include_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"; -include_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"; - +include_once DOL_DOCUMENT_ROOT . "/accountancy/class/bookkeeping.class.php"; +include_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php"; +include_once DOL_DOCUMENT_ROOT . "/core/lib/date.lib.php"; /** * Class lettering */ class lettering extends BookKeeping { - /** - * lettrageTiers - * - * @param int $socid Thirdparty id - * @return void - */ + /** + * lettrageTiers + * + * @param int $socid Thirdparty id + * @return void + */ public function lettrageTiers($socid) { - $db = $this->db; $object = new Societe($this->db); $object->id = $socid; $object->fetch($socid); - - if( $object->code_compta == '411CUSTCODE') + if ($object->code_compta == '411CUSTCODE') { $object->code_compta = ''; + } - if( $object->code_compta_fournisseur == '401SUPPCODE') + if ($object->code_compta_fournisseur == '401SUPPCODE') { $object->code_compta_fournisseur = ''; + } - - - $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.lettering_code, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering "; + /*$sql = "SELECT DISTINCT bk.rowid, bk.lettering_code"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE code_journal = 'BQ' AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) AND ( "; + if (! empty($object->code_compta)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) $sql .= " OR "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + if (! empty($object->code_compta_fournisseur)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) AND ( bk.date_lettering ='' OR bk.date_lettering IS NULL ) AND bk.lettering_code !='' "; + $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; + $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; - $sql .= " GROUP BY bk.lettering_code "; - - - $resql = $db->query ( $sql ); + $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows ( $resql ); + $num = $db->num_rows($resql); $i = 0; while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); - $i++; + $obj = $db->fetch_object($resql); + $i ++; - $sql = "SELECT bk.rowid "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE bk.lettering_code = '".$obj->lettering_code."' "; - $sql .= " AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) - $sql .= " OR "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; -// echo $sql; - $resql2 = $db->query ( $sql ); - if ($resql2) { - $num2 = $db->num_rows ( $resql2 ); - $i2 = 0; - $ids = array(); - while ( $i2 < $num2 ) { - $obj2 = $db->fetch_object ( $resql2 ); - $i2++; - $ids[] = $obj2->rowid; - } - - - if(count($ids) > 1 ){ - $result = $this->updatelettrage($ids); - - // var_dump($result); -// if( $result < 0 ){ -// setEventMessages('', $BookKeeping->errors, 'errors' ); -// $error++; -// -// } - } + $sql = "SELECT bk.rowid "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; + $sql .= " WHERE bk.lettering_code = '" . $obj->lettering_code . "' "; + $sql .= " AND ( "; + if (! empty($object->code_compta)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) + $sql .= " OR "; + if (! empty($object->code_compta_fournisseur)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; + $sql .= " ) "; + // echo $sql; + $resql2 = $db->query($sql); + if ($resql2) { + $num2 = $db->num_rows($resql2); + $i2 = 0; + $ids = array(); + while ( $obj2 = $db->fetch_object($resql2) ) { + $ids[] = $obj2->rowid; } - } - } + if (count($ids) > 1) { + $result = $this->updatelettrage($ids); + } + } + } + } else { + setEventMessage($this->db->lasterror,'errors'); + return -1; + }*/ /** - Prise en charge des lettering complexe avec prelevment , virement - */ - $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type "; + * Prise en charge des lettering complexe avec prelevment , virement + */ + $sql = "SELECT DISTINCT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.thirdparty_code, "; + $sql .= " bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant "; + $sql .= " , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu ON(bk.fk_doc = bu.fk_bank AND bu.type IN ('payment', 'payment_supplier') ) "; - $sql .= " WHERE code_journal = 'BQ' AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) + $sql .= " WHERE ( "; + if (! empty($object->code_compta)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) $sql .= " OR "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; + if (! empty($object->code_compta_fournisseur)) + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) AND date_lettering ='' "; - $sql .= " GROUP BY bk.lettering_code "; + $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; + $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; + $sql.= $db->order('bk.doc_date','DESC'); -// echo $sql; -// - $resql = $db->query ( $sql ); + // echo $sql; + // + $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows ( $resql ); - $i = 0; + $num = $db->num_rows($resql); - while ( $i < $num ) { - $obj = $db->fetch_object ( $resql ); + while ( $obj = $db->fetch_object($resql)) { $ids = array(); - $i++; + $ids_fact = array(); - // print_r($obj); + if ($obj->type == 'payment_supplier') { - - - if($obj->type =='payment_supplier' ) { - $ids[] = $obj->rowid; - - $sql= 'SELECT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank '; - $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.ref) "; - // $sqlmid.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc ON soc.rowid=facf.fk_soc"; - // $sqlmid.= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement as payc ON payc.id=payf.fk_paiement"; - $sql .= " WHERE 1 "; - $sql .= " AND fk_paiementfourn = '".$obj->url_id."' "; - // $sql .= " AND (bk.numero_compte = '" . $object->code_compta . "' OR bk.numero_compte = '" . $object->code_compta_fournisseur . "') "; - $sql .= " AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) - $sql .= " OR "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; - // echo $sql; - // exit; + $sql = 'SELECT DISTINCT bk.rowid, facf.ref, facf.ref_supplier, payf.fk_bank, facf.rowid as fact_id'; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = payf.fk_bank AND bk.code_journal='".$obj->code_journal."')"; + $sql .= " WHERE payfacf.fk_paiementfourn = '" . $obj->url_id . "' "; + $sql .= " AND code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) "; + $sql .= " AND ( "; + if (! empty($object->code_compta)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; } - elseif($obj->type =='payment' ){ - $ids[] = $obj->rowid; - - $sql= 'SELECT bk.rowid,fac.facnumber , pay.fk_bank '; - $sql.= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sql.= " INNER JOIN " .MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid) "; - $sql .= " WHERE 1 "; - $sql .= " AND payfac.fk_paiement = '".$obj->url_id."' "; - $sql .= " AND ( "; - if(!empty($object->code_compta) ) - $sql .= " bk.code_tiers = '" . $object->code_compta . "' "; - if(!empty($object->code_compta) && !empty($object->code_compta_fournisseur) ) - $sql .= " OR "; - if(!empty($object->code_compta_fournisseur) ) - $sql .= " bk.code_tiers = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; - - // echo $sql; + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) { + $sql .= " OR "; } + if (! empty($object->code_compta_fournisseur)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; + } + $sql .= " ) "; - - $resql2 = $db->query ( $sql ); + $resql2 = $db->query($sql); if ($resql2) { - $num2 = $db->num_rows ( $resql2 ); - $i2 = 0; - - while ( $i2 < $num2 ) { - $obj2 = $db->fetch_object ( $resql2 ); - $i2++; - $ids[] = $obj2->rowid; + while ($obj2 = $db->fetch_object($resql2)) { + $ids[$obj2->rowid] = $obj2->rowid; + $ids_fact[] = $obj2->fact_id; } - // print_r($ids); - // exit; - if(count($ids) > 1 ){ - $result = $this->updatelettrage($ids); - - // var_dump($result); -// if( $result < 0 ){ -// setEventMessages('', $BookKeeping->errors, 'errors' ); -// $error++; -// -// } - } - - // exit; + } else { + $this->errors[] = $this->db->lasterror; + return -1; } + if (count($ids_fact)) { + $sql = 'SELECT bk.rowid, facf.ref, facf.ref_supplier '; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.rowid AND facf.rowid IN (".implode(',',$ids_fact)."))"; + $sql .= " WHERE bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=3) "; + $sql .= " AND ( "; + if (! empty($object->code_compta)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + } + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) { + $sql .= " OR "; + } + if (! empty($object->code_compta_fournisseur)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; + } + $sql .= " ) "; + + $resql2 = $db->query($sql); + if ($resql2) { + while ($obj2 = $db->fetch_object($resql2)) { + $ids[$obj2->rowid] = $obj2->rowid; + } + + } else { + $this->errors[] = $this->db->lasterror; + return -1; + } + } + + } elseif ($obj->type == 'payment') { + + + $sql = 'SELECT DISTINCT bk.rowid, fac.ref, fac.ref, pay.fk_bank, fac.rowid as fact_id'; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture fac "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='".$obj->code_journal."')"; + $sql .= " WHERE payfac.fk_paiement = '" . $obj->url_id . "' "; + $sql .= " AND bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) "; + $sql .= " AND ( "; + if (! empty($object->code_compta)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + } + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) { + $sql .= " OR "; + } + if (! empty($object->code_compta_fournisseur)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; + } + $sql .= " ) "; + + + $resql2 = $db->query($sql); + if ($resql2) { + while ($obj2 = $db->fetch_object($resql2)) { + $ids[$obj2->rowid] = $obj2->rowid; + $ids_fact[] = $obj2->fact_id; + } + + } else { + $this->errors[] = $this->db->lasterror; + return -1; + } + if (count($ids_fact)) { + $sql = 'SELECT bk.rowid, fac.ref, fac.ref_supplier '; + $sql .= " FROM " . MAIN_DB_PREFIX . "facture fac "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (".implode(',',$ids_fact)."))"; + $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=2) "; + $sql .= " AND ( "; + if (! empty($object->code_compta)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; + } + if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) { + $sql .= " OR "; + } + if (! empty($object->code_compta_fournisseur)) { + $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; + } + $sql .= " ) "; + + $resql2 = $db->query($sql); + if ($resql2) { + while ($obj2 = $db->fetch_object($resql2)) { + $ids[$obj2->rowid] = $obj2->rowid; + } + + } else { + $this->errors[] = $this->db->lasterror; + return -1; + } + } + } + + if (count($ids) > 1) { + $result = $this->updatelettrage($ids); + } + } } - - + if ($error) { + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::".__METHOD__ . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + return - 1 * $error; + } else { + return 1; + } } - - public function updatelettrage($ids, $notrigger=false){ + /** + * + * @param array $ids + * @param string $notrigger + * @return number + */ + public function updateLettrage($ids = array(), $notrigger = false) { $error = 0; - $sql = "SELECT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; - $sql .= " lettering_code != '' GROUP BY lettering_code ORDER BY lettering_code DESC limit 1; "; -// echo $sql; - $result = $this->db->query ( $sql ); + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); + + $sql = "SELECT DISTINCT lettering_code FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; + $sql .= " lettering_code != '' ORDER BY lettering_code DESC limit 1; "; + + $result = $this->db->query($sql); if ($result) { - $obj = $this->db->fetch_object ( $result ); - $lettre = (empty($obj->lettering_code)? 'AAA' : $obj->lettering_code ); - if(!empty($obj->lettering_code)) - $lettre++; + $obj = $this->db->fetch_object($result); + $lettre = (empty($obj->lettering_code) ? 'AAA' : $obj->lettering_code); + if (! empty($obj->lettering_code)) + $lettre ++; + } else { + $this->errors[] = 'Error' . $this->db->lasterror(); + ; + $error ++; } - else{ - $this->errors[] = 'Error'.$this->db->lasterror();; - $error++; - } -// var_dump(__line__, $error); $sql = "SELECT SUM(ABS(debit)) as deb, SUM(ABS(credit)) as cred FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE "; - $sql .= " rowid IN (".implode(',', $ids).") "; - $result = $this->db->query ( $sql ); + $sql .= " rowid IN (" . implode(',', $ids) . ") "; + $result = $this->db->query($sql); if ($result) { - $obj = $this->db->fetch_object ( $result ); -// print_r($obj); - if( !(round(abs($obj->deb),2) === round(abs($obj->cred),2)) ){ -// echo $sql; -// print_r($obj); - $this->errors[] = 'Total not exacts '.round(abs($obj->deb),2).' vs '. round(abs($obj->cred),2); - $error++; + $obj = $this->db->fetch_object($result); + if (! (round(abs($obj->deb), 2) === round(abs($obj->cred), 2))) { + $this->errors[] = 'Total not exacts ' . round(abs($obj->deb), 2) . ' vs ' . round(abs($obj->cred), 2); + $error ++; } + } else { + $this->errors[] = 'Erreur sql' . $this->db->lasterror(); + ; + $error ++; } - else{ - $this->errors[] = 'Erreur sql'.$this->db->lasterror();; - $error++; - } - // Update request $now = dol_now(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping SET"; - $sql.= " lettering_code='".$lettre."'"; - $sql.= " , date_lettering = " .$now ; // todo correct date it's false - $sql.= " WHERE rowid IN (".implode(',', $ids).") "; -// echo $sql ; -// -// var_dump(__line__, $error); -// print_r($this->errors); -// exit; + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET"; + $sql .= " lettering_code='" . $lettre . "'"; + $sql .= " , date_lettering = '" . $this->db->idate($now)."'"; // todo correct date it's false + $sql .= " WHERE rowid IN (" . implode(',', $ids) . ") "; $this->db->begin(); - dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); - $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = "Error " . $this->db->lasterror(); + } - if (! $error) - { - if (! $notrigger) - { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. + if (! $error) { + if (! $notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - } + // // Call triggers + // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + // $interface=new Interfaces($this->db); + // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + // if ($result < 0) { $error++; $this->errors=$interface->errors; } + // // End call triggers } -// var_dump(__line__, $error); - // Commit or rollback - if ($error) - { -// foreach($this->errors as $errmsg) -// { -// dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); -// $this->error.=($this->error?', '.$errmsg:$errmsg); -// } - $this->db->rollback(); -// echo $this->error; -// var_dump(__line__, $error); - return -1*$error; - } - else - { - $this->db->commit(); - return 1; + } + // Commit or rollback + if ($error) { + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::update " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); } + $this->db->rollback(); + return - 1 * $error; + } else { + $this->db->commit(); + return 1; + } } - } diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index bfa0c342245..5a0c76e3c1a 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -432,6 +432,7 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; + $bookkeeping->date_lim_reglement = $now; // No subledger_account value for the bank line if ($tabtype[$key] == 'payment') { @@ -493,6 +494,7 @@ if (! $error && $action == 'writebookkeeping') { $bookkeeping->journal_label = $journal_label; $bookkeeping->fk_user_author = $user->id; $bookkeeping->date_create = $now; + $bookkeeping->date_lim_reglement = $now; if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice $bookkeeping->label_operation = ''; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 159e7a6435a..6a5f6e34a62 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -123,6 +123,24 @@ function societe_prepare_head(Societe $object) $h++; } + // Tab to accountancy + if (! empty($conf->accounting->enabled) && $object->client>0) + { + $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage.php?socid='.$object->id; + $head[$h][1] = $langs->trans("TabAccountingCustomer"); + $head[$h][2] = 'accounting'; + $h++; + } + + // Tab to accountancy + if (! empty($conf->accounting->enabled) && $object->fournisseur>0) + { + $head[$h][0] = DOL_URL_ROOT.'/accountancy/bookkeeping/thirdparty_lettrage_supplier.php?socid='.$object->id; + $head[$h][1] = $langs->trans("TabAccountingSupplier"); + $head[$h][2] = 'accounting_supplier'; + $h++; + } + // Related items if (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fichinter->enabled) || ! empty($conf->fournisseur->enabled)) { From 18bd2c444528fbd72004d26142d01eaecdb50e7a Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 2 Oct 2017 09:04:22 +0200 Subject: [PATCH 004/148] fix travis --- htdocs/accountancy/class/lettering.class.php | 104 ++++--------------- 1 file changed, 21 insertions(+), 83 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index e94c33d69e5..7fe58d92072 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -52,59 +52,6 @@ class lettering extends BookKeeping $object->code_compta_fournisseur = ''; } - /*$sql = "SELECT DISTINCT bk.rowid, bk.lettering_code"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) AND ( "; - if (! empty($object->code_compta)) - $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; - if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) - $sql .= " OR "; - if (! empty($object->code_compta_fournisseur)) - $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; - - $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; - $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; - - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - - while ( $i < $num ) { - $obj = $db->fetch_object($resql); - $i ++; - - $sql = "SELECT bk.rowid "; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; - $sql .= " WHERE bk.lettering_code = '" . $obj->lettering_code . "' "; - $sql .= " AND ( "; - if (! empty($object->code_compta)) - $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; - if (! empty($object->code_compta) && ! empty($object->code_compta_fournisseur)) - $sql .= " OR "; - if (! empty($object->code_compta_fournisseur)) - $sql .= " bk.thirdparty_code = '" . $object->code_compta_fournisseur . "' "; - $sql .= " ) "; - // echo $sql; - $resql2 = $db->query($sql); - if ($resql2) { - $num2 = $db->num_rows($resql2); - $i2 = 0; - $ids = array(); - while ( $obj2 = $db->fetch_object($resql2) ) { - $ids[] = $obj2->rowid; - } - - if (count($ids) > 1) { - $result = $this->updatelettrage($ids); - } - } - } - } else { - setEventMessage($this->db->lasterror,'errors'); - return -1; - }*/ - /** * Prise en charge des lettering complexe avec prelevment , virement */ @@ -123,7 +70,7 @@ class lettering extends BookKeeping $sql .= " ) AND (bk.date_lettering ='' OR bk.date_lettering IS NULL) "; $sql .= " AND (bk.lettering_code != '' OR bk.lettering_code IS NULL) "; - $sql.= $db->order('bk.doc_date','DESC'); + $sql .= $db->order('bk.doc_date', 'DESC'); // echo $sql; // @@ -131,7 +78,7 @@ class lettering extends BookKeeping if ($resql) { $num = $db->num_rows($resql); - while ( $obj = $db->fetch_object($resql)) { + while ( $obj = $db->fetch_object($resql) ) { $ids = array(); $ids_fact = array(); @@ -141,9 +88,9 @@ class lettering extends BookKeeping $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = payf.fk_bank AND bk.code_journal='".$obj->code_journal."')"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = payf.fk_bank AND bk.code_journal='" . $obj->code_journal . "')"; $sql .= " WHERE payfacf.fk_paiementfourn = '" . $obj->url_id . "' "; - $sql .= " AND code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) "; + $sql .= " AND code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=4) "; $sql .= " AND ( "; if (! empty($object->code_compta)) { $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; @@ -156,23 +103,21 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); if ($resql2) { - while ($obj2 = $db->fetch_object($resql2)) { + while ( $obj2 = $db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; $ids_fact[] = $obj2->fact_id; } - } else { $this->errors[] = $this->db->lasterror; - return -1; + return - 1; } if (count($ids_fact)) { $sql = 'SELECT bk.rowid, facf.ref, facf.ref_supplier '; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.rowid AND facf.rowid IN (".implode(',',$ids_fact)."))"; - $sql .= " WHERE bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=3) "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = facf.rowid AND facf.rowid IN (" . implode(',', $ids_fact) . "))"; + $sql .= " WHERE bk.code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=3) "; $sql .= " AND ( "; if (! empty($object->code_compta)) { $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; @@ -187,26 +132,23 @@ class lettering extends BookKeeping $resql2 = $db->query($sql); if ($resql2) { - while ($obj2 = $db->fetch_object($resql2)) { + while ( $obj2 = $db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; } - } else { $this->errors[] = $this->db->lasterror; - return -1; + return - 1; } } - } elseif ($obj->type == 'payment') { - $sql = 'SELECT DISTINCT bk.rowid, fac.ref, fac.ref, pay.fk_bank, fac.rowid as fact_id'; $sql .= " FROM " . MAIN_DB_PREFIX . "facture fac "; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='".$obj->code_journal."')"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON (bk.fk_doc = pay.fk_bank AND bk.code_journal='" . $obj->code_journal . "')"; $sql .= " WHERE payfac.fk_paiement = '" . $obj->url_id . "' "; - $sql .= " AND bk.code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=4) "; + $sql .= " AND bk.code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=4) "; $sql .= " AND ( "; if (! empty($object->code_compta)) { $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; @@ -219,23 +161,21 @@ class lettering extends BookKeeping } $sql .= " ) "; - $resql2 = $db->query($sql); if ($resql2) { - while ($obj2 = $db->fetch_object($resql2)) { + while ( $obj2 = $db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; $ids_fact[] = $obj2->fact_id; } - } else { $this->errors[] = $this->db->lasterror; - return -1; + return - 1; } if (count($ids_fact)) { $sql = 'SELECT bk.rowid, fac.ref, fac.ref_supplier '; $sql .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (".implode(',',$ids_fact)."))"; - $sql .= " WHERE code_journal IN (SELECT code FROM ".MAIN_DB_PREFIX."accounting_journal WHERE nature=2) "; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk ON( bk.fk_doc = fac.rowid AND fac.rowid IN (" . implode(',', $ids_fact) . "))"; + $sql .= " WHERE code_journal IN (SELECT code FROM " . MAIN_DB_PREFIX . "accounting_journal WHERE nature=2) "; $sql .= " AND ( "; if (! empty($object->code_compta)) { $sql .= " bk.thirdparty_code = '" . $object->code_compta . "' "; @@ -250,13 +190,12 @@ class lettering extends BookKeeping $resql2 = $db->query($sql); if ($resql2) { - while ($obj2 = $db->fetch_object($resql2)) { + while ( $obj2 = $db->fetch_object($resql2) ) { $ids[$obj2->rowid] = $obj2->rowid; } - } else { $this->errors[] = $this->db->lasterror; - return -1; + return - 1; } } } @@ -264,12 +203,11 @@ class lettering extends BookKeeping if (count($ids) > 1) { $result = $this->updatelettrage($ids); } - } } if ($error) { foreach ( $this->errors as $errmsg ) { - dol_syslog(get_class($this) . "::".__METHOD__ . $errmsg, LOG_ERR); + dol_syslog(get_class($this) . "::" . __METHOD__ . $errmsg, LOG_ERR); $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); } return - 1 * $error; @@ -281,7 +219,7 @@ class lettering extends BookKeeping /** * * @param array $ids - * @param string $notrigger + * @param boolean $notrigger * @return number */ public function updateLettrage($ids = array(), $notrigger = false) { @@ -325,7 +263,7 @@ class lettering extends BookKeeping $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_bookkeeping SET"; $sql .= " lettering_code='" . $lettre . "'"; - $sql .= " , date_lettering = '" . $this->db->idate($now)."'"; // todo correct date it's false + $sql .= " , date_lettering = '" . $this->db->idate($now) . "'"; // todo correct date it's false $sql .= " WHERE rowid IN (" . implode(',', $ids) . ") "; $this->db->begin(); From 123c9d2315466292bad0761d3437d95d7ec06276 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 3 Oct 2017 18:12:17 +0200 Subject: [PATCH 005/148] Better fix only if bdd is pgsql --- htdocs/adherents/list.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 1334bc2ba7e..e439cfadc31 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -83,6 +83,7 @@ $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search // List of fields to search into when doing a "search in all" $fieldstosearchall = array( + 'd.rowid'=>'Ref', 'd.login'=>'Login', 'd.lastname'=>'Lastname', 'd.firstname'=>'Firstname', @@ -95,6 +96,7 @@ $fieldstosearchall = array( 'd.note_public'=>'NotePublic', 'd.note_private'=>'NotePrivate', ); +if($db->type == 'pgsql') unset($fieldstosearchall['d.rowid']); $arrayfields=array( 'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), 'd.lastname'=>array('label'=>$langs->trans("Lastname"), 'checked'=>1), From 56acb2c08cff743396009702877c8454b1d462f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 5 Oct 2017 10:38:58 +0200 Subject: [PATCH 006/148] Fix: with 5.0 and 6.0, supplier prices are always in main currency. The currency is not yet available in supplier prices. Field to define the currency of supplier prices were added in database but not yet used by screen/code. --- htdocs/fourn/class/fournisseur.commande.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index ab02abb4733..822ff7a7b5c 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1408,8 +1408,7 @@ class CommandeFournisseur extends CommonOrder $result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->fk_soc); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref/$this->fk_soc if ($result > 0) { - $pu = 0; // Unit price supplier price set by get_buyprice - $pu_ht_devise = $prod->fourn_pu; // With multicurrency, supplier price is related to its currency, $pu will be calculated (= $pu_ht_devise if exchange rate is 1) + $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice $ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice } if ($result == 0) // If result == 0, we failed to found the supplier reference price From b213c7ed24f357195929a1d69d5d9ba22971384c Mon Sep 17 00:00:00 2001 From: John Date: Tue, 10 Oct 2017 14:15:06 +0200 Subject: [PATCH 007/148] Fix extrafields transmition from supplier order to supplier invoice --- htdocs/fourn/facture/card.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index ca9689292b4..7ce51fc572c 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1432,6 +1432,10 @@ if ($action == 'create') $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datetmp); $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); $datedue=($datetmp==''?-1:$datetmp); + + // Replicate extrafields + $objectsrc->fetch_optionals($originid); + $object->array_options = $objectsrc->array_options; } } else From fd796723f22ba06fe9845326874bc69f307479ef Mon Sep 17 00:00:00 2001 From: arnaud Date: Tue, 10 Oct 2017 17:15:01 +0200 Subject: [PATCH 008/148] FIX bankentries search conciliated if val 0 --- htdocs/compta/bank/bankentries.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/compta/bank/bankentries.php b/htdocs/compta/bank/bankentries.php index cec3d648450..8491ca45b09 100644 --- a/htdocs/compta/bank/bankentries.php +++ b/htdocs/compta/bank/bankentries.php @@ -372,6 +372,8 @@ if (dol_strlen($search_dv_end) > 0) $param .= '&search_end_dvmonth=' . GETPOST if ($search_req_nb) $param.='&req_nb='.urlencode($search_req_nb); if (GETPOST("thirdparty")) $param.='&thirdparty='.urlencode(GETPOST("thirdparty")); if ($optioncss != '') $param.='&optioncss='.$optioncss; +if(!empty($search_conciliated) || $search_conciliated === 0) $param.='&search_conciliated='.$search_conciliated; + // Add $param from extra fields foreach ($search_array_options as $key => $val) { From 1e7676d26fbe2bc89da30985e92c8bdc9fb031b6 Mon Sep 17 00:00:00 2001 From: gauthier Date: Thu, 12 Oct 2017 09:30:04 +0200 Subject: [PATCH 009/148] FIX : wrong key in selectarray --- htdocs/compta/facture/stats/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index 5c5aa8489be..4d9fdebeb64 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -232,7 +232,7 @@ $tmp_companies = $form->select_thirdparty_list($socid,'socid',$filter,1, 0, 0, a $companies = array(); foreach ($tmp_companies as $value) { - $companies[$value['value']] = $value['label']; + $companies[$value['key']] = $value['label']; } print '
'; From 463441c80866ae4424ba18db9eed709a9d8bfd82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 12 Oct 2017 18:32:10 +0200 Subject: [PATCH 010/148] Fix bad table name --- htdocs/install/mysql/migration/repair.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index 467455e57de..66224c17ea5 100755 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -33,7 +33,7 @@ -- VMYSQLUTF8UNICODECI ALTER TABLE llx_stock_mouvement MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) CHARACTER SET utf8; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_lot MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci; --- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_batchlot MODIFY batch VARCHAR(30) CHARACTER SET utf8; +-- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_batch MODIFY batch VARCHAR(30) CHARACTER SET utf8; -- VMYSQLUTF8UNICODECI ALTER TABLE llx_product_batch MODIFY batch VARCHAR(30) COLLATE utf8_unicode_ci; From b491d22c16c52c87e6f70e1a5c15480e85fbf2bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 14 Oct 2017 02:30:33 +0200 Subject: [PATCH 011/148] FIX selection of thirdparty was lost on stats page of invoices --- htdocs/compta/facture/stats/index.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index bf54e4f58ab..6d2a15ceb8f 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -227,12 +227,13 @@ complete_head_from_modules($conf,$langs,null,$head,$h,$type); dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1); -$tmp_companies = $form->select_thirdparty_list($socid,'socid',$filter,1, 0, 0, array(), '', 1); +// We use select_thirdparty_list instead of select_company so we can use $filter and share same code for customer and supplier. +$tmp_companies = $form->select_thirdparty_list($socid, 'socid', $filter, 1, 0, 0, array(), '', 1); //Array passed as an argument to Form::selectarray to build a proper select input $companies = array(); foreach ($tmp_companies as $value) { - $companies[$value['value']] = $value['label']; + $companies[$value['key']] = $value['label']; } print '
'; From c44207f7d36279cce6483cd9fe8b86930c8a21d0 Mon Sep 17 00:00:00 2001 From: BENKE Charlene Date: Sat, 14 Oct 2017 12:39:39 +0200 Subject: [PATCH 012/148] template file not only odt/ods --- htdocs/core/lib/functions2.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 3d2e2bb359b..044a885aded 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1606,7 +1606,8 @@ function getListOfModels($db,$type,$maxfilenamelength=0) if (! $tmpdir) { unset($listofdir[$key]); continue; } if (is_dir($tmpdir)) { - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); + // all type of template is allowed + $tmpfiles=dol_dir_list($tmpdir, 'files', 0, '', '', 'name', SORT_ASC, 0); if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); } } From 75835dd7fd99f322b703b77d05e9cd2bb11343d3 Mon Sep 17 00:00:00 2001 From: Papoteur Date: Sun, 15 Oct 2017 13:33:48 +0200 Subject: [PATCH 013/148] Add Autofill button for amount to pay in charge payment page --- htdocs/compta/paiement_charge.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 398f70ad36a..95426b824a1 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -169,6 +169,20 @@ if ($action == 'create') $charge->paiementtype=$charge->mode_reglement_id?$charge->mode_reglement_id:$charge->paiementtype; $total = $charge->amount; + if (! empty($conf->use_javascript_ajax)) + { + print "\n".''."\n"; + } print load_fiche_titre($langs->trans("DoPayment")); print "
\n"; @@ -294,7 +308,12 @@ if ($action == 'create') if ($sumpaid < $objp->amount) { $namef = "amount_".$objp->id; - print ''; + $nameRemain = "remain_".$objp->id; + if (!empty($conf->use_javascript_ajax)) + print img_picto("Auto fill",'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'"); + $remaintopay=$objp->amount - $sumpaid; + print ''; + print ''; } else { From bd5bffa72c21c7e2a2dcd3d0aa2aceda8afe36f8 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Mon, 16 Oct 2017 06:47:05 +0000 Subject: [PATCH 014/148] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- htdocs/accountancy/class/lettering.class.php | 14 +- .../admin/dolistore/class/dolistore.class.php | 536 ++-- htdocs/admin/mails_senderprofile_list.php | 414 +-- htdocs/collab/index.php | 500 ++-- htdocs/commande/card.php | 494 ++-- htdocs/compta/facture/card.php | 1222 ++++----- htdocs/compta/facture/fiche-rec.php | 1534 +++++------ htdocs/contrat/card.php | 2440 ++++++++-------- .../core/class/emailsenderprofile.class.php | 20 +- htdocs/core/class/html.formfile.class.php | 2442 ++++++++--------- htdocs/core/class/html.formmail.class.php | 1102 ++++---- .../class/expensereport_rule.class.php | 22 +- htdocs/fourn/commande/card.php | 1634 +++++------ htdocs/fourn/facture/card.php | 2004 +++++++------- htdocs/main.inc.php | 2436 ++++++++-------- htdocs/societe/rib.php | 236 +- htdocs/supplier_proposal/card.php | 424 +-- htdocs/websites/index.php | 2 +- scripts/emailings/mailing-send.php | 94 +- 19 files changed, 8785 insertions(+), 8785 deletions(-) diff --git a/htdocs/accountancy/class/lettering.class.php b/htdocs/accountancy/class/lettering.class.php index f3d9359b19d..423a3e54b02 100644 --- a/htdocs/accountancy/class/lettering.class.php +++ b/htdocs/accountancy/class/lettering.class.php @@ -33,12 +33,12 @@ include_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php"; */ class lettering extends BookKeeping { - /** - * lettrageTiers - * - * @param int $socid Thirdparty id - * @return int <0 if KO, >0 if OK - */ + /** + * lettrageTiers + * + * @param int $socid Thirdparty id + * @return int <0 if KO, >0 if OK + */ public function lettrageTiers($socid) { $db = $this->db; @@ -121,7 +121,7 @@ class lettering extends BookKeeping /** Prise en charge des lettering complexe avec prelevment , virement - */ + */ $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens , bk.code_journal , bk.piece_num, bk.date_lettering, bu.url_id , bu.type "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as bk"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu ON(bk.fk_doc = bu.fk_bank AND bu.type IN ('payment', 'payment_supplier') ) "; diff --git a/htdocs/admin/dolistore/class/dolistore.class.php b/htdocs/admin/dolistore/class/dolistore.class.php index 84ec9457532..07dbec4b902 100644 --- a/htdocs/admin/dolistore/class/dolistore.class.php +++ b/htdocs/admin/dolistore/class/dolistore.class.php @@ -25,119 +25,119 @@ include_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/PSWebServiceLibrary.class */ class Dolistore { - // params - public $start; // beginning of pagination - public $end; // end of pagination - public $per_page; // pagination: display per page - public $categorie; // the current categorie - public $search; // the search keywords + // params + public $start; // beginning of pagination + public $end; // end of pagination + public $per_page; // pagination: display per page + public $categorie; // the current categorie + public $search; // the search keywords - // setups - public $url; // the url of this page - public $shop_url; // the url of the shop - public $vat_rate; // the vat rate used in the shop (prices are provided without vat) - public $lang; // the integer representing the lang in the store - public $debug_api; // usefull if no dialog + // setups + public $url; // the url of this page + public $shop_url; // the url of the shop + public $vat_rate; // the vat rate used in the shop (prices are provided without vat) + public $lang; // the integer representing the lang in the store + public $debug_api; // usefull if no dialog - /** - * Constructor - */ - function __construct() - { - global $conf, $langs; + /** + * Constructor + */ + function __construct() + { + global $conf, $langs; - $this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace'; - $this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product='; - $this->vat_rate = 1.2; // 20% de TVA - $this->debug_api = false; + $this->url = DOL_URL_ROOT.'/admin/modules.php?mode=marketplace'; + $this->shop_url = 'https://www.dolistore.com/index.php?controller=product&id_product='; + $this->vat_rate = 1.2; // 20% de TVA + $this->debug_api = false; - $langtmp = explode('_', $langs->defaultlang); - $lang = $langtmp[0]; - $lang_array = array('en'=>0, 'fr'=>1, 'es'=>2, 'it'=>3, 'de'=>4); // Into table ps_lang of Prestashop - 1 - if (! in_array($lang, array_keys($lang_array))) $lang = 'en'; - $this->lang = $lang_array[$lang]; - } + $langtmp = explode('_', $langs->defaultlang); + $lang = $langtmp[0]; + $lang_array = array('en'=>0, 'fr'=>1, 'es'=>2, 'it'=>3, 'de'=>4); // Into table ps_lang of Prestashop - 1 + if (! in_array($lang, array_keys($lang_array))) $lang = 'en'; + $this->lang = $lang_array[$lang]; + } - /** - * Load data from remote Dolistore market place. - * This fills ->categories - * - * @param array $options Options - * @return void - */ - function getRemoteData($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0)) - { - global $conf, $langs; + /** + * Load data from remote Dolistore market place. + * This fills ->categories + * + * @param array $options Options + * @return void + */ + function getRemoteData($options = array('start' => 0, 'end' => 10, 'per_page' => 50, 'categorie' => 0)) + { + global $conf, $langs; - $this->start = $options['start']; - $this->end = $options['end']; - $this->per_page = $options['per_page']; - $this->categorie = $options['categorie']; - $this->search = $options['search']; + $this->start = $options['start']; + $this->end = $options['end']; + $this->per_page = $options['per_page']; + $this->categorie = $options['categorie']; + $this->search = $options['search']; - if ($this->end == 0) { - $this->end = $this->per_page; - } + if ($this->end == 0) { + $this->end = $this->per_page; + } - try { - $this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, - $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api); + try { + $this->api = new PrestaShopWebservice($conf->global->MAIN_MODULE_DOLISTORE_API_SRV, + $conf->global->MAIN_MODULE_DOLISTORE_API_KEY, $this->debug_api); - // Here we set the option array for the Webservice : we want products resources - $opt = array(); - $opt['resource'] = 'products'; + // Here we set the option array for the Webservice : we want products resources + $opt = array(); + $opt['resource'] = 'products'; - // make a search to limit the id returned. - if ($this->search != '') { - $opt2 = array(); - $opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang; - // Call - $xml = $this->api->get($opt2); - $products = array(); - foreach ($xml->products->children() as $product) { - $products[] = (int) $product['id']; - } - $opt['filter[id]'] = '['.implode('|', $products).']'; - } elseif ($this->categorie != 0) { - $opt2 = array(); - $opt2['resource'] = 'categories'; - $opt2['id'] = $this->categorie; - // Call - $xml = $this->api->get($opt2); - $products = array(); - foreach ($xml->category->associations->products->children() as $product) { - $products[] = (int) $product->id; - } - $opt['filter[id]'] = '['.implode('|', $products).']'; - } - $opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]'; - $opt['sort'] = 'id_desc'; - $opt['filter[active]'] = '[1]'; - $opt['limit'] = "$this->start,$this->end"; + // make a search to limit the id returned. + if ($this->search != '') { + $opt2 = array(); + $opt2['url'] = $conf->global->MAIN_MODULE_DOLISTORE_API_SRV.'/api/search?query='.$this->search.'&language='.$this->lang; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->products->children() as $product) { + $products[] = (int) $product['id']; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } elseif ($this->categorie != 0) { + $opt2 = array(); + $opt2['resource'] = 'categories'; + $opt2['id'] = $this->categorie; + // Call + $xml = $this->api->get($opt2); + $products = array(); + foreach ($xml->category->associations->products->children() as $product) { + $products[] = (int) $product->id; + } + $opt['filter[id]'] = '['.implode('|', $products).']'; + } + $opt['display'] = '[id,name,id_default_image,id_category_default,reference,price,condition,show_price,date_add,date_upd,description_short,description,module_version,dolibarr_min,dolibarr_max]'; + $opt['sort'] = 'id_desc'; + $opt['filter[active]'] = '[1]'; + $opt['limit'] = "$this->start,$this->end"; // $opt['filter[id]'] contais list of product id that are result of search - // Call API to get the detail - $xml = $this->api->get($opt); - $this->products = $xml->products->children(); + // Call API to get the detail + $xml = $this->api->get($opt); + $this->products = $xml->products->children(); - // Here we set the option array for the Webservice : we want categories resources - $opt = array(); - $opt['resource'] = 'categories'; - $opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]'; - $opt['sort'] = 'id_asc'; - // Call - $xml = $this->api->get($opt); - $this->categories = $xml->categories->children(); - } catch (PrestaShopWebserviceException $e) { - // Here we are dealing with errors - $trace = $e->getTrace(); - if ($trace[0]['args'][0] == 404) die('Bad ID'); - else if ($trace[0]['args'][0] == 401) die('Bad auth key'); - else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); - } - } + // Here we set the option array for the Webservice : we want categories resources + $opt = array(); + $opt['resource'] = 'categories'; + $opt['display'] = '[id,id_parent,nb_products_recursive,active,is_root_category,name,description]'; + $opt['sort'] = 'id_asc'; + // Call + $xml = $this->api->get($opt); + $this->categories = $xml->categories->children(); + } catch (PrestaShopWebserviceException $e) { + // Here we are dealing with errors + $trace = $e->getTrace(); + if ($trace[0]['args'][0] == 404) die('Bad ID'); + else if ($trace[0]['args'][0] == 401) die('Bad auth key'); + else die('Can not access to '.$conf->global->MAIN_MODULE_DOLISTORE_API_SRV); + } + } /** * Return tree of Dolistore categories. $this->categories must have been loaded before. @@ -145,199 +145,199 @@ class Dolistore * @param int $parent Id of parent category * @return string */ - function get_categories($parent = 0) - { - if (!isset($this->categories)) die('not possible'); - if ($parent != 0) { - $html = '
    '; - } else { - $html = ''; - } + function get_categories($parent = 0) + { + if (!isset($this->categories)) die('not possible'); + if ($parent != 0) { + $html = '
      '; + } else { + $html = ''; + } - $nbofcateg = count($this->categories); - for ($i = 0; $i < $nbofcateg; $i++) - { - $cat = $this->categories[$i]; - if ($cat->is_root_category == 1 && $parent == 0) { - $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.'

      '; - $html .= self::get_categories($cat->id); - $html .= "
    • \n"; - } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau - $select = ($cat->id == $this->categorie) ? ' selected' : ''; - $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.''; - $html .= self::get_categories($cat->id); - $html .= "
    • \n"; - } else { + $nbofcateg = count($this->categories); + for ($i = 0; $i < $nbofcateg; $i++) + { + $cat = $this->categories[$i]; + if ($cat->is_root_category == 1 && $parent == 0) { + $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.'

      '; + $html .= self::get_categories($cat->id); + $html .= "
    • \n"; + } elseif (trim($cat->id_parent) == $parent && $cat->active == 1 && trim($cat->id_parent) != 0) { // si cat est de ce niveau + $select = ($cat->id == $this->categorie) ? ' selected' : ''; + $html .= '
    • '.$cat->name->language[$this->lang].' '.$cat->nb_products_recursive.''; + $html .= self::get_categories($cat->id); + $html .= "
    • \n"; + } else { - } - } + } + } - if ($html == '
        ') { - return ''; - } - if ($parent != 0) { - return $html.'
      '; - } else { - return $html; - } - } + if ($html == '
        ') { + return ''; + } + if ($parent != 0) { + return $html.'
      '; + } else { + return $html; + } + } - /** - * Return list of product formated for output - * - * @return string HTML output - */ - function get_products() - { - global $langs, $conf; - $html = ""; - $parity = "pair"; - $last_month = time() - (30 * 24 * 60 * 60); - foreach ($this->products as $product) { - $parity = ($parity == "impair") ? 'pair' : 'impair'; + /** + * Return list of product formated for output + * + * @return string HTML output + */ + function get_products() + { + global $langs, $conf; + $html = ""; + $parity = "pair"; + $last_month = time() - (30 * 24 * 60 * 60); + foreach ($this->products as $product) { + $parity = ($parity == "impair") ? 'pair' : 'impair'; - // check new product ? - $newapp = ''; - if ($last_month < strtotime($product->date_add)) { - $newapp .= ''.$langs->trans('New').' '; - } + // check new product ? + $newapp = ''; + if ($last_month < strtotime($product->date_add)) { + $newapp .= ''.$langs->trans('New').' '; + } - // check updated ? - if ($last_month < strtotime($product->date_upd) && $newapp == '') { - $newapp .= ''.$langs->trans('Updated').' '; - } + // check updated ? + if ($last_month < strtotime($product->date_upd) && $newapp == '') { + $newapp .= ''.$langs->trans('Updated').' '; + } - // add image or default ? - if ($product->id_default_image != '') { - $image_url = DOL_URL_ROOT.'/admin/dolistore/ajax/image.php?id_product='.$product->id.'&id_image='.$product->id_default_image; - $images = ''. - ''; - } else { - $images = ''; - } + // add image or default ? + if ($product->id_default_image != '') { + $image_url = DOL_URL_ROOT.'/admin/dolistore/ajax/image.php?id_product='.$product->id.'&id_image='.$product->id_default_image; + $images = ''. + ''; + } else { + $images = ''; + } - // free or pay ? - if ($product->price > 0) { - $price = '

      '.price(round((float) $product->price * $this->vat_rate, 2)).' €

      '; - $download_link = ''; - } else { - $price = '

      '.$langs->trans('Free').'

      '; - $download_link = ''; - $download_link.= '

      '; - } + // free or pay ? + if ($product->price > 0) { + $price = '

      '.price(round((float) $product->price * $this->vat_rate, 2)).' €

      '; + $download_link = ''; + } else { + $price = '

      '.$langs->trans('Free').'

      '; + $download_link = ''; + $download_link.= '

      '; + } - //checking versions - if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) { - if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) { - //compatible - $version = ''.$langs->trans('CompatibleUpTo', $product->dolibarr_max, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = ''; - } else { - //never compatible, module expired - $version = ''.$langs->trans('NotCompatible', DOL_VERSION, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = 'NotCompatible'; - } - } else { - //need update - $version = ''.$langs->trans('CompatibleAfterUpdate', DOL_VERSION, - $product->dolibarr_min, $product->dolibarr_max).''; - $compatible = 'NotCompatible'; - } + //checking versions + if ($this->version_compare($product->dolibarr_min, DOL_VERSION) <= 0) { + if ($this->version_compare($product->dolibarr_max, DOL_VERSION) >= 0) { + //compatible + $version = ''.$langs->trans('CompatibleUpTo', $product->dolibarr_max, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = ''; + } else { + //never compatible, module expired + $version = ''.$langs->trans('NotCompatible', DOL_VERSION, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = 'NotCompatible'; + } + } else { + //need update + $version = ''.$langs->trans('CompatibleAfterUpdate', DOL_VERSION, + $product->dolibarr_min, $product->dolibarr_max).''; + $compatible = 'NotCompatible'; + } - //.'
      '.$langs->trans("SeeInMarkerPlace").' + //.'
      '.$langs->trans("SeeInMarkerPlace").' - //output template - $html .= ' + //output template + $html .= '
      '.$newapp.$images.'

      '.$product->name->language[$this->lang] - .'
      '.$version.'

      + .'
      '.$version.' '.dol_print_date(dol_stringtotime($product->date_upd), 'dayhour').' - '.$langs->trans('Ref').': '.$product->reference.' - '.$langs->trans('Id').': '.$product->id.'

      '.$product->description_short->language[$this->lang].' '.$product->description->language[$this->lang].' '.$price.' '.$download_link.' '; - } - return $html; - } + } + return $html; + } - function get_previous_link($text = '<<') - { - return ''.$text.''; - } + function get_previous_link($text = '<<') + { + return ''.$text.''; + } - function get_next_link($text = '>>') - { - return ''.$text.''; - } + function get_next_link($text = '>>') + { + return ''.$text.''; + } - function get_previous_url() - { - $param_array = array(); - if ($this->start < $this->per_page) { - $sub = 0; - } else { - $sub = $this->per_page; - } - $param_array['start'] = $this->start - $sub; - $param_array['end'] = $this->end - $sub; - if ($this->categorie != 0) { - $param_array['categorie'] = $this->categorie; - } - $param = http_build_query($param_array); - return $this->url."&".$param; - } + function get_previous_url() + { + $param_array = array(); + if ($this->start < $this->per_page) { + $sub = 0; + } else { + $sub = $this->per_page; + } + $param_array['start'] = $this->start - $sub; + $param_array['end'] = $this->end - $sub; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."&".$param; + } - function get_next_url() - { - $param_array = array(); - if (count($this->products) < $this->per_page) { - $add = 0; - } else { - $add = $this->per_page; - } - $param_array['start'] = $this->start + $add; - $param_array['end'] = $this->end + $add; - if ($this->categorie != 0) { - $param_array['categorie'] = $this->categorie; - } - $param = http_build_query($param_array); - return $this->url."&".$param; - } + function get_next_url() + { + $param_array = array(); + if (count($this->products) < $this->per_page) { + $add = 0; + } else { + $add = $this->per_page; + } + $param_array['start'] = $this->start + $add; + $param_array['end'] = $this->end + $add; + if ($this->categorie != 0) { + $param_array['categorie'] = $this->categorie; + } + $param = http_build_query($param_array); + return $this->url."&".$param; + } - function version_compare($v1, $v2) - { - $v1 = explode('.', $v1); - $v2 = explode('.', $v2); - $ret = 0; - $level = 0; - $count1 = count($v1); - $count2 = count($v2); - $maxcount = max($count1, $count2); - while ($level < $maxcount) { - $operande1 = isset($v1[$level]) ? $v1[$level] : 'x'; - $operande2 = isset($v2[$level]) ? $v2[$level] : 'x'; - $level++; - if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') { - break; - } - if ($operande1 < $operande2) { - $ret = -$level; - break; - } - if ($operande1 > $operande2) { - $ret = $level; - break; - } - } - //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'
      '."\n"; - return $ret; - } + function version_compare($v1, $v2) + { + $v1 = explode('.', $v1); + $v2 = explode('.', $v2); + $ret = 0; + $level = 0; + $count1 = count($v1); + $count2 = count($v2); + $maxcount = max($count1, $count2); + while ($level < $maxcount) { + $operande1 = isset($v1[$level]) ? $v1[$level] : 'x'; + $operande2 = isset($v2[$level]) ? $v2[$level] : 'x'; + $level++; + if (strtoupper($operande1) == 'X' || strtoupper($operande2) == 'X' || $operande1 == '*' || $operande2 == '*') { + break; + } + if ($operande1 < $operande2) { + $ret = -$level; + break; + } + if ($operande1 > $operande2) { + $ret = $level; + break; + } + } + //print join('.',$versionarray1).'('.count($versionarray1).') / '.join('.',$versionarray2).'('.count($versionarray2).') => '.$ret.'
      '."\n"; + return $ret; + } } diff --git a/htdocs/admin/mails_senderprofile_list.php b/htdocs/admin/mails_senderprofile_list.php index 91f0a3a8037..2190705ea8b 100644 --- a/htdocs/admin/mails_senderprofile_list.php +++ b/htdocs/admin/mails_senderprofile_list.php @@ -85,7 +85,7 @@ if (! $sortorder) $sortorder="ASC"; $socid=0; if ($user->societe_id > 0) { - //$socid = $user->societe_id; + //$socid = $user->societe_id; accessforbidden(); } @@ -94,14 +94,14 @@ $search_all=trim(GETPOST("search_all",'alpha')); $search=array(); foreach($object->fields as $key => $val) { - if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); + if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha'); } // List of fields to search into when doing a "search in all" $fieldstosearchall = array(); foreach($object->fields as $key => $val) { - if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label']; + if ($val['searchall']) $fieldstosearchall['t.'.$key]=$val['label']; } // Definition of fields for list @@ -109,15 +109,15 @@ $arrayfields=array(); foreach($object->fields as $key => $val) { // If $val['visible']==0, then we never show the field - if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled']); + if (! empty($val['visible'])) $arrayfields['t.'.$key]=array('label'=>$val['label'], 'checked'=>(($val['visible']<0)?0:1), 'enabled'=>$val['enabled']); } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); - } + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); + } } @@ -136,32 +136,32 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - // Purge search criteria - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers - { - foreach($object->fields as $key => $val) - { - $search[$key]=''; - } - $toselect=''; - $search_array_options=array(); - } - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha') - || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha')) - { - $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation - } + // Purge search criteria + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers + { + foreach($object->fields as $key => $val) + { + $search[$key]=''; + } + $toselect=''; + $search_array_options=array(); + } + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha') + || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha')) + { + $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } - // Mass actions - $objectclass='EmailSenderProfile'; - $objectlabel='EmailSenderProfile'; - $permtoread = $user->admin; - $permtodelete = $user->admin; - $uploaddir = $conf->admin->dir_output.'/senderprofiles'; - include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + // Mass actions + $objectclass='EmailSenderProfile'; + $objectlabel='EmailSenderProfile'; + $permtoread = $user->admin; + $permtodelete = $user->admin; + $uploaddir = $conf->admin->dir_output.'/senderprofiles'; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -196,7 +196,7 @@ dol_fiche_head($head, 'senderprofiles', '', -1); $sql = 'SELECT '; foreach($object->fields as $key => $val) { - $sql.='t.'.$key.', '; + $sql.='t.'.$key.', '; } // Add fields from extrafields foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); @@ -217,16 +217,16 @@ if ($search_all) $sql.= natural_search(array_keys($fieldstosearchall), $search_a // Add where from extra fields foreach ($search_array_options as $key => $val) { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - $typ=$extrafields->attribute_type[$tmpkey]; - $mode_search=0; - if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric - if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int - if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0')) - { - $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); - } + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $typ=$extrafields->attribute_type[$tmpkey]; + $mode_search=0; + if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric + if (in_array($typ, array('sellist')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int + if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0')) + { + $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); + } } // Add where from hooks $parameters=array(); @@ -263,8 +263,8 @@ dol_syslog($script_file, LOG_DEBUG); $resql=$db->query($sql); if (! $resql) { - dol_print_error($db); - exit; + dol_print_error($db); + exit; } $num = $db->num_rows($resql); @@ -272,10 +272,10 @@ $num = $db->num_rows($resql); // Direct jump if only one record found if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all) { - $obj = $db->fetch_object($resql); - $id = $obj->rowid; - header("Location: ".DOL_URL_ROOT.'/monmodule/emailsenderprofile_card.php?id='.$id); - exit; + $obj = $db->fetch_object($resql); + $id = $obj->rowid; + header("Location: ".DOL_URL_ROOT.'/monmodule/emailsenderprofile_card.php?id='.$id); + exit; } @@ -301,21 +301,21 @@ if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&con if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); foreach($search as $key => $val) { - $param.= '&search_'.$key.'='.urlencode($search[$key]); + $param.= '&search_'.$key.'='.urlencode($search[$key]); } if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); // Add $param from extra fields foreach ($search_array_options as $key => $val) { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } // List of mass actions available $arrayofmassactions = array( - //'presend'=>$langs->trans("SendByMail"), - //'builddoc'=>$langs->trans("PDFMerge"), + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), ); if ($user->rights->monmodule->delete) $arrayofmassactions['delete']=$langs->trans("Delete"); if ($massaction == 'presend') $arrayofmassactions=array(); @@ -347,7 +347,7 @@ if (! empty($moreforfilter)) { print '
      '; print $moreforfilter; - print '
      '; + print '
'; } $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; @@ -363,35 +363,35 @@ print ''; foreach($object->fields as $key => $val) { - if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; - if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print ''; + if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) - { - if (! empty($arrayfields["ef.".$key]['checked'])) - { - $align=$extrafields->getAlignFlag($key); - $typeofextrafield=$extrafields->attribute_type[$key]; - print ''; - } - } + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + } + } } // Fields from hook $parameters=array('arrayfields'=>$arrayfields); @@ -400,12 +400,12 @@ print $hookmanager->resPrint; // Rest of fields search foreach($object->fields as $key => $val) { - if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; - if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print ''; + if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) print ''; } // Action column print ''."\n"; print ''; foreach($object->fields as $key => $val) { - if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; - if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) - { + if (! empty($arrayfields["ef.".$key]['checked'])) + { $align=$extrafields->getAlignFlag($key); $sortonfield = "ef.".$key; if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; print getTitleFieldOfList($langs->trans($extralabels[$key]), 0, $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align?'align="'.$align.'"':''), $sortfield, $sortorder)."\n"; - } + } } } // Hook fields @@ -448,12 +448,12 @@ print $hookmanager->resPrint; // Rest of fields title foreach($object->fields as $key => $val) { - if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; - if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; + if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.=' nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($align?'class="'.$align.'"':''), $sortfield, $sortorder, $align.' ')."\n"; } print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ')."\n"; print ''."\n"; @@ -463,7 +463,7 @@ print ''."\n"; $needToFetchEachLine=0; foreach ($extrafields->attribute_computed as $key => $val) { - if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object + if (preg_match('/\$object/',$val)) $needToFetchEachLine++; // There is at least one compute field that use $object } @@ -473,42 +473,42 @@ $i=0; $totalarray=array(); while ($i < min($num, $limit)) { - $obj = $db->fetch_object($resql); - if (empty($obj)) break; // Should not happen + $obj = $db->fetch_object($resql); + if (empty($obj)) break; // Should not happen - // Store properties in $object + // Store properties in $object $object->id = $obj->rowid; foreach($object->fields as $key => $val) { if (isset($obj->$key)) $object->$key = $obj->$key; } - // Show here line of result - print ''; - foreach($object->fields as $key => $val) - { - if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; - if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) - { - print ''; - if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); - elseif ($key == 'ref') print $object->getNomUrl(1, '', 0, '', 1); - elseif ($key == 'status') print $object->getLibStatut(3); - else print $obj->$key; - print ''; - if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; - $totalarray['val']['t.'.$key] += $obj->$key; - } - } - } - // Extra fields + // Show here line of result + print ''; + foreach($object->fields as $key => $val) + { + if (in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align='center'; + if (in_array($val['type'], array('timestamp'))) $align.='nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'ref') print $object->getNomUrl(1, '', 0, '', 1); + elseif ($key == 'status') print $object->getLibStatut(3); + else print $obj->$key; + print ''; + if (! $i) $totalarray['nbfield']++; + if (! empty($val['isameasure'])) + { + if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; + $totalarray['val']['t.'.$key] += $obj->$key; + } + } + } + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { foreach($extrafields->attribute_label as $key => $val) @@ -522,86 +522,86 @@ while ($i < min($num, $limit)) $tmpkey='options_'.$key; print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); print ''; - if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; - $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; - } + if (! $i) $totalarray['nbfield']++; + if (! empty($val['isameasure'])) + { + if (! $i) $totalarray['pos'][$totalarray['nbfield']]='ef.'.$tmpkey; + $totalarray['val']['ef.'.$tmpkey] += $obj->$tmpkey; + } } } } - // Fields from hook + // Fields from hook $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - // Rest of fields - foreach($object->fields as $key => $val) - { - if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; - $align=''; - if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; - if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; - if ($key == 'status') $align.=($align?' ':'').'center'; - if (! empty($arrayfields['t.'.$key]['checked'])) - { - print ''; - if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); - elseif ($key == 'status') print $object->getLibStatut(3); - else print $obj->$key; - print ''; - if (! $i) $totalarray['nbfield']++; - if (! empty($val['isameasure'])) - { - if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; - $totalarray['val']['t.'.$key] += $obj->$key; - } - } - } - // Action column - print ''; + if (! $i) $totalarray['nbfield']++; + if (! empty($val['isameasure'])) + { + if (! $i) $totalarray['pos'][$totalarray['nbfield']]='t.'.$key; + $totalarray['val']['t.'.$key] += $obj->$key; + } + } + } + // Action column + print ''; - if (! $i) $totalarray['nbfield']++; + if (! $i) $totalarray['nbfield']++; - print ''; + print ''; - $i++; + $i++; } // Show total line if (isset($totalarray['pos'])) { - print ''; - $i=0; - while ($i < $totalarray['nbfield']) - { - $i++; - if (! empty($totalarray['pos'][$i])) print ''; - else - { - if ($i == 1) - { - if ($num < $limit) print ''; - else print ''; - } - else print ''; - } - } - print ''; + print ''; + $i=0; + while ($i < $totalarray['nbfield']) + { + $i++; + if (! empty($totalarray['pos'][$i])) print ''; + else + { + if ($i == 1) + { + if ($num < $limit) print ''; + else print ''; + } + else print ''; + } + } + print ''; } // If no record found if ($num == 0) { - $colspan=1; - foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } - print ''; + $colspan=1; + foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; } + print ''; } @@ -618,25 +618,25 @@ print ''."\n"; if (in_array('builddoc',$arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) { - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) - { - require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); - $formfile = new FormFile($db); + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) + { + require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'); + $formfile = new FormFile($db); - // Show list of available documents - $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; - $urlsource.=str_replace('&','&',$param); + // Show list of available documents + $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; + $urlsource.=str_replace('&','&',$param); - $filedir=$diroutputmassaction; - $genallowed=$user->rights->monmodule->read; - $delallowed=$user->rights->monmodule->read; + $filedir=$diroutputmassaction; + $genallowed=$user->rights->monmodule->read; + $delallowed=$user->rights->monmodule->read; - print $formfile->showdocuments('massfilesarea_monmodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); - } - else - { - print '
'.$langs->trans("ShowTempMassFilesArea").''; - } + print $formfile->showdocuments('massfilesarea_monmodule','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); + } + else + { + print '
'.$langs->trans("ShowTempMassFilesArea").''; + } } dol_fiche_end(); diff --git a/htdocs/collab/index.php b/htdocs/collab/index.php index 3cba48cfc07..bcc12c0a341 100644 --- a/htdocs/collab/index.php +++ b/htdocs/collab/index.php @@ -36,7 +36,7 @@ if (! $user->admin) accessforbidden(); if (! ((GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))) { - $conf->dol_hide_leftmenu = 1; // Force hide of left menu. + $conf->dol_hide_leftmenu = 1; // Force hide of left menu. } $error=0; @@ -71,33 +71,33 @@ if (GETPOST('refreshpage')) $action='preview'; // Add a collab page if ($action == 'add') { - $db->begin(); + $db->begin(); - $objectpage->title = GETPOST('WEBSITE_TITLE'); - $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); - $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); - $objectpage->keywords = GETPOST('WEBSITE_KEYWORD'); + $objectpage->title = GETPOST('WEBSITE_TITLE'); + $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); + $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); + $objectpage->keywords = GETPOST('WEBSITE_KEYWORD'); - if (empty($objectpage->title)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); - $error++; - } + if (empty($objectpage->title)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); + $error++; + } - if (! $error) - { - $res = $objectpage->create($user); - if ($res <= 0) - { - $error++; - setEventMessages($objectpage->error, $objectpage->errors, 'errors'); - } - } + if (! $error) + { + $res = $objectpage->create($user); + if ($res <= 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + } if (! $error) { $db->commit(); - setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); - $action=''; + setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); + $action=''; } else { @@ -111,38 +111,38 @@ if ($action == 'add') // Update page if ($action == 'delete') { - $db->begin(); + $db->begin(); - $res = $object->fetch(0, $website); + $res = $object->fetch(0, $website); - $res = $objectpage->fetch($pageid, $object->fk_website); + $res = $objectpage->fetch($pageid, $object->fk_website); - if ($res > 0) - { - $res = $objectpage->delete($user); - if (! $res > 0) - { - $error++; - setEventMessages($objectpage->error, $objectpage->errors, 'errors'); - } + if ($res > 0) + { + $res = $objectpage->delete($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } - if (! $error) - { - $db->commit(); - setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website); - exit; - } - else - { - $db->rollback(); - } - } - else - { - dol_print_error($db); - } + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website); + exit; + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + } } @@ -161,7 +161,7 @@ print "\n".'
'; print ''; if ($action == 'create') { - print ''; + print ''; } @@ -174,225 +174,225 @@ print '
'; if (count($object->records) > 0) { - // ***** Part for web sites + // ***** Part for web sites - print '
'; - print $langs->trans("Website").': '; - print '
'; + print '
'; + print $langs->trans("Website").': '; + print '
'; - // List of websites - print '
'; - $out=''; - $out.=''; + if (empty($object->records)) $out.=''; + // Loop on each sites + $i=0; + foreach($object->records as $key => $valwebsite) + { + if (empty($website)) $website=$valwebsite->ref; - $out.=''; - $i++; - } - $out.=''; - $out.=ajax_combobox('website'); - print $out; - print ''; + $out.=''; + $i++; + } + $out.=''; + $out.=ajax_combobox('website'); + print $out; + print ''; - if ($website) - { - $virtualurl=''; - $dataroot=DOL_DATA_ROOT.'/websites/'.$website; - if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; - } + if ($website) + { + $virtualurl=''; + $dataroot=DOL_DATA_ROOT.'/websites/'.$website; + if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; + } - if ($website && $action == 'preview') - { - $disabled=''; - if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; + if ($website && $action == 'preview') + { + $disabled=''; + if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; - print '   '; + print '   '; - //print ''; - print ''; - print ''; - print ''; - } + //print ''; + print ''; + print ''; + print ''; + } - print '
'; + print '
'; - // Button for websites - print '
'; + // Button for websites + print '
'; - if ($action == 'preview') - { - print '
'; - print ''; - //print ''; - $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); - print $form->textwithpicto('', $htmltext); - print '
'; + if ($action == 'preview') + { + print '
'; + print ''; + //print ''; + $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); + print $form->textwithpicto('', $htmltext); + print '
'; - $urlext=$virtualurl; - $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; - //if (! empty($object->virtualhost)) - //{ - print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">'; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); - print ''; - //} + $urlext=$virtualurl; + $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; + //if (! empty($object->virtualhost)) + //{ + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + //} - print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); - print ''; - } + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); + print ''; + } - if (in_array($action, array('editcss','editmenu','create'))) - { - if ($action != 'preview') print ''; - if (preg_match('/^create/',$action)) print ''; - if (preg_match('/^edit/',$action)) print ''; - } + if (in_array($action, array('editcss','editmenu','create'))) + { + if ($action != 'preview') print ''; + if (preg_match('/^create/',$action)) print ''; + if (preg_match('/^edit/',$action)) print ''; + } - print '
'; + print '
'; - // ***** Part for pages + // ***** Part for pages - if ($website) - { - print '
'; + if ($website) + { + print ''; - $array=$objectpage->fetchAll($object->id); - if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); - $atleastonepage=(is_array($array) && count($array) > 0); + $array=$objectpage->fetchAll($object->id); + if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); + $atleastonepage=(is_array($array) && count($array) > 0); - print '
'; - print '
'; - print $langs->trans("Page").': '; - print '
'; - print '
'; + print '
'; + print '
'; + print $langs->trans("Page").': '; + print '
'; + print '
'; - if ($action != 'add') - { - $out=''; - $out.=''; + if ($atleastonepage) + { + if (empty($pageid) && $action != 'create') // Page id is not defined, we try to take one + { + $firstpageid=0;$homepageid=0; + foreach($array as $key => $valpage) + { + if (empty($firstpageid)) $firstpageid=$valpage->id; + if ($object->fk_default_home && $key == $object->fk_default_home) $homepageid=$valpage->id; + } + $pageid=$homepageid?$homepageid:$firstpageid; // We choose home page and if not defined yet, we take first page + } - foreach($array as $key => $valpage) - { - $out.=''; - } - } - else $out.=''; - $out.=''; - $out.=ajax_combobox('pageid'); - print $out; - } - else - { - print $langs->trans("New"); - } + foreach($array as $key => $valpage) + { + $out.=''; + } + } + else $out.=''; + $out.=''; + $out.=ajax_combobox('pageid'); + print $out; + } + else + { + print $langs->trans("New"); + } - print ''; - //print $form->selectarray('page', $array); + print ''; + //print $form->selectarray('page', $array); - if ($action == 'preview') - { - $disabled=''; - if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; + if ($action == 'preview') + { + $disabled=''; + if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; - if ($pageid > 0) - { - print '   '; + if ($pageid > 0) + { + print '   '; - if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; - else print ''; - print ''; - print ''; - //print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; - //print ''.dol_escape_htmltag($langs->trans("EditPageContent")).''; - print ''; - } - } + if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; + else print ''; + print ''; + print ''; + //print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; + //print ''.dol_escape_htmltag($langs->trans("EditPageContent")).''; + print ''; + } + } - print '
'; - print '
'; - print '
'; + print '
'; + print '
'; + print '
'; - print '
'; + print '
'; - if ($website && $pageid > 0 && $action == 'preview') - { - $websitepage = new WebSitePage($db); - $websitepage->fetch($pageid); + if ($website && $pageid > 0 && $action == 'preview') + { + $websitepage = new WebSitePage($db); + $websitepage->fetch($pageid); - $realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; - $pagealias = $websitepage->pageurl; + $realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; + $pagealias = $websitepage->pageurl; - print '
'; - print ''; - //print ''; - $htmltext=$langs->trans("WEBSITE_PAGENAME", $pagealias); - print $form->textwithpicto('', $htmltext); - print '
'; + print '
'; + print ''; + //print ''; + $htmltext=$langs->trans("WEBSITE_PAGENAME", $pagealias); + print $form->textwithpicto('', $htmltext); + print '
'; - if (! empty($object->virtualhost)) - { - $urlext=$virtualurl.'/'.$pagealias.'.php'; - print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); - print ''; - } - else - { - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); - print ''; - } + if (! empty($object->virtualhost)) + { + $urlext=$virtualurl.'/'.$pagealias.'.php'; + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } + else + { + print ''; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } - print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">'; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); - print ''; // View page in new Tab - //print ''; + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); + print ''; // View page in new Tab + //print ''; - // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext - } - if (! in_array($action, array('editcss','editmenu','create'))) - { - if ($action != 'preview') print ''; - if (preg_match('/^create/',$action)) print ''; - if (preg_match('/^edit/',$action)) print ''; - } + // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext + } + if (! in_array($action, array('editcss','editmenu','create'))) + { + if ($action != 'preview') print ''; + if (preg_match('/^create/',$action)) print ''; + if (preg_match('/^edit/',$action)) print ''; + } - print '
'; + print '
'; - if ($action == 'preview') - { - // Adding jquery code to change on the fly url of preview ext - if (! empty($conf->use_javascript_ajax)) - { - print ''; - } - } - } + } + } + } } else { - print '
'; - $langs->load("errors"); - print $langs->trans("ErrorModuleSetupNotComplete"); - print '
'; - $action=''; + print '
'; + $langs->load("errors"); + print $langs->trans("ErrorModuleSetupNotComplete"); + print '
'; + $action=''; } @@ -437,21 +437,21 @@ $head = array(); if ($action == 'editcontent') { - /* + /* * Editing global variables not related to a specific theme */ - $csscontent = @file_get_contents($filecss); + $csscontent = @file_get_contents($filecss); - $contentforedit = ''; - /*$contentforedit.=''."\n";*/ - $contentforedit .= $objectpage->content; + $contentforedit .= $objectpage->content; - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%'); - $doleditor->Create(0, '', false); + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%'); + $doleditor->Create(0, '', false); } print "
\n\n"; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index c385fe9a6ae..1de02c5df7f 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -170,7 +170,7 @@ if (empty($reshook)) $result = $object->set_reopen($user); if ($result > 0) { - setEventMessages($langs->trans('OrderReopened', $object->ref), null); + setEventMessages($langs->trans('OrderReopened', $object->ref), null); } else { @@ -264,12 +264,12 @@ if (empty($reshook)) $object->modelpdf = GETPOST('model'); $object->cond_reglement_id = GETPOST('cond_reglement_id'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); - $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_account = GETPOST('fk_account', 'int'); $object->availability_id = GETPOST('availability_id'); $object->demand_reason_id = GETPOST('demand_reason_id'); $object->date_livraison = $datelivraison; - $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); - $object->warehouse_id = GETPOST('warehouse_id', 'int'); + $object->shipping_method_id = GETPOST('shipping_method_id', 'int'); + $object->warehouse_id = GETPOST('warehouse_id', 'int'); $object->fk_delivery_address = GETPOST('fk_address'); $object->contactid = GETPOST('contactid'); $object->fk_incoterms = GETPOST('incoterm_id', 'int'); @@ -279,8 +279,8 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form if (! $error) { - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error++; + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; } // If creation from another object of another module (Example: origin=propal, originid=1) @@ -366,7 +366,7 @@ if (empty($reshook)) // Extrafields if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if - // trigger used + // trigger used { $lines[$i]->fetch_optionals($lines[$i]->rowid); $array_options = $lines[$i]->array_options; @@ -423,7 +423,7 @@ if (empty($reshook)) $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if ($reshook < 0) - $error++; + $error++; } else { setEventMessages($object->error, $object->errors, 'errors'); @@ -491,10 +491,10 @@ if (empty($reshook)) } else if ($action == 'classifyunbilled' && $user->rights->commande->creer) { - $ret=$object->classifyUnBilled(); - if ($ret < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + $ret=$object->classifyUnBilled(); + if ($ret < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // Positionne ref commande client @@ -502,7 +502,7 @@ if (empty($reshook)) $result = $object->set_ref_client($user, GETPOST('ref_client')); if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -510,7 +510,7 @@ if (empty($reshook)) $result = $object->set_remise($user, GETPOST('remise')); if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -563,7 +563,7 @@ if (empty($reshook)) else if ($action == 'setavailability' && $user->rights->commande->creer) { $result = $object->availability(GETPOST('availability_id')); if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } else if ($action == 'setdemandreason' && $user->rights->commande->creer) { @@ -596,36 +596,36 @@ if (empty($reshook)) // Set incoterm elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } + { + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } // bank account else if ($action == 'setbankaccount' && $user->rights->commande->creer) { - $result=$object->setBankAccount(GETPOST('fk_account', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // shipping method else if ($action == 'setshippingmethod' && $user->rights->commande->creer) { - $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } - // warehouse - else if ($action == 'setwarehouse' && $user->rights->commande->creer) { - $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } + // warehouse + else if ($action == 'setwarehouse' && $user->rights->commande->creer) { + $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else if ($action == 'setremisepercent' && $user->rights->commande->creer) { $result = $object->set_remise($user, GETPOST('remise_percent')); @@ -898,18 +898,18 @@ if (empty($reshook)) unset($_POST['idprod']); unset($_POST['units']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); } else { setEventMessages($object->error, $object->errors, 'errors'); } @@ -1062,13 +1062,13 @@ if (empty($reshook)) } else if ($action == 'confirm_validate' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) ) { $idwarehouse = GETPOST('idwarehouse'); - $qualified_for_stock_change=0; + $qualified_for_stock_change=0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change=$object->hasProductsOrServices(2); @@ -1121,7 +1121,7 @@ if (empty($reshook)) else if ($action == 'confirm_modif' && $user->rights->commande->creer) { $idwarehouse = GETPOST('idwarehouse'); - $qualified_for_stock_change=0; + $qualified_for_stock_change=0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change=$object->hasProductsOrServices(2); @@ -1174,13 +1174,13 @@ if (empty($reshook)) } else if ($action == 'confirm_cancel' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) ) { $idwarehouse = GETPOST('idwarehouse'); - $qualified_for_stock_change=0; + $qualified_for_stock_change=0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change=$object->hasProductsOrServices(2); @@ -1223,7 +1223,7 @@ if (empty($reshook)) $hookmanager->initHooks(array('orderdao')); $parameters = array('id' => $object->id); $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by - // some hooks + // some hooks if (empty($reshook)) { $result = $object->insertExtraFields(); if ($result < 0) { @@ -1393,10 +1393,10 @@ if ($action == 'create' && $user->rights->commande->creer) $soc = $objectsrc->thirdparty; $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); + $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); $availability_id = (!empty($objectsrc->availability_id)?$objectsrc->availability_id:(!empty($soc->availability_id)?$soc->availability_id:0)); - $shipping_method_id = (! empty($objectsrc->shipping_method_id)?$objectsrc->shipping_method_id:(! empty($soc->shipping_method_id)?$soc->shipping_method_id:0)); - $warehouse_id = (! empty($objectsrc->warehouse_id)?$objectsrc->warehouse_id:(! empty($soc->warehouse_id)?$soc->warehouse_id:0)); + $shipping_method_id = (! empty($objectsrc->shipping_method_id)?$objectsrc->shipping_method_id:(! empty($soc->shipping_method_id)?$soc->shipping_method_id:0)); + $warehouse_id = (! empty($objectsrc->warehouse_id)?$objectsrc->warehouse_id:(! empty($soc->warehouse_id)?$soc->warehouse_id:0)); $demand_reason_id = (!empty($objectsrc->demand_reason_id)?$objectsrc->demand_reason_id:(!empty($soc->demand_reason_id)?$soc->demand_reason_id:0)); $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); @@ -1421,10 +1421,10 @@ if ($action == 'create' && $user->rights->commande->creer) { $cond_reglement_id = $soc->cond_reglement_id; $mode_reglement_id = $soc->mode_reglement_id; - $fk_account = $soc->fk_account; + $fk_account = $soc->fk_account; $availability_id = $soc->availability_id; - $shipping_method_id = $soc->shipping_method_id; - $warehouse_id = $soc->warehouse_id; + $shipping_method_id = $soc->shipping_method_id; + $warehouse_id = $soc->warehouse_id; $demand_reason_id = $soc->demand_reason_id; $remise_percent = $soc->remise_percent; $remise_absolue = 0; @@ -1537,12 +1537,12 @@ if ($action == 'create' && $user->rights->commande->creer) $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); print ''; - // Bank Account + // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && ! empty($conf->banque->enabled)) { print '
'; + $form->select_comptes($fk_account, 'fk_account', 0, '', 1); + print ''; } // Delivery delay @@ -1550,21 +1550,21 @@ if ($action == 'create' && $user->rights->commande->creer) $form->selectAvailabilityDelay($availability_id, 'availability_id', '', 1); print ''; - // Shipping Method - if (! empty($conf->expedition->enabled)) { - print ''; - } + // Shipping Method + if (! empty($conf->expedition->enabled)) { + print ''; + } - // Warehouse - if (! empty($conf->expedition->enabled) && ! empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct=new FormProduct($db); - print ''; - } + // Warehouse + if (! empty($conf->expedition->enabled) && ! empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct=new FormProduct($db); + print ''; + } // What trigger creation print ''; print ''; - print ''; } // Other attributes $parameters = array('objectsrc' => $objectsrc, 'socid'=>$socid); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by - print $hookmanager->resPrint; + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } @@ -1623,8 +1623,8 @@ if ($action == 'create' && $user->rights->commande->creer) { print ''; print ''; - print ''; } @@ -1918,69 +1918,69 @@ if ($action == 'create' && $user->rights->commande->creer) // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); + // Thirdparty + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' ('.$langs->trans("OtherOrders").')'; - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->commande->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.=''; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } - $morehtmlref.=''; + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->commande->creer) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.=''; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.=''; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - print '
'; - print '
'; - print '
'; + print '
'; + print '
'; + print '
'; - print '
'; - if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key])) - { - $crit=$val; - $tmpkey=preg_replace('/search_options_/','',$key); - $searchclass=''; - if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; - if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; - print ''; - } - print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')) && empty($extrafields->attribute_computed[$key])) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; @@ -420,25 +420,25 @@ print '
'; + print $hookmanager->resPrint; + // Rest of fields + foreach($object->fields as $key => $val) + { + if (! in_array($key, array('date_creation', 'tms', 'import_key', 'status'))) continue; + $align=''; + if (in_array($val['type'], array('date','datetime','timestamp'))) $align.=($align?' ':'').'center'; + if (in_array($val['type'], array('timestamp'))) $align.=($align?' ':'').'nowrap'; + if ($key == 'status') $align.=($align?' ':'').'center'; + if (! empty($arrayfields['t.'.$key]['checked'])) + { + print ''; + if (in_array($val['type'], array('date','datetime','timestamp'))) print dol_print_date($db->jdate($obj->$key), 'dayhour'); + elseif ($key == 'status') print $object->getLibStatut(3); + else print $obj->$key; + print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { - $selected=0; + { + $selected=0; if (in_array($obj->rowid, $arrayofselected)) $selected=1; print ''; - } + } print '
'.price($totalarray['val'][$totalarray['pos'][$i]]).''.$langs->trans("Total").''.$langs->trans("Totalforthispage").'
'.price($totalarray['val'][$totalarray['pos'][$i]]).''.$langs->trans("Total").''.$langs->trans("Totalforthispage").'
'.$langs->trans("NoRecordFound").'
'.$langs->trans("NoRecordFound").'
' . $langs->trans('BankAccount') . ''; - $form->select_comptes($fk_account, 'fk_account', 0, '', 1); - print '
' . $langs->trans('SendingMethod') . ''; - print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); - print '
' . $langs->trans('SendingMethod') . ''; + print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); + print '
' . $langs->trans('Warehouse') . ''; - print $formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1); - print '
' . $langs->trans('Warehouse') . ''; + print $formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1); + print '
' . $langs->trans('Source') . ''; @@ -1590,22 +1590,22 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
'; - $incoterm_id = GETPOST('incoterm_id'); - $incoterm_location = GETPOST('location_incoterms'); - if (empty($incoterm_id)) - { - $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); - $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); - } - print $form->select_incoterms($incoterm_id, $incoterm_location); + print ''; + $incoterm_id = GETPOST('incoterm_id'); + $incoterm_location = GETPOST('location_incoterms'); + if (empty($incoterm_id)) + { + $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); + $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); + } + print $form->select_incoterms($incoterm_id, $incoterm_location); print '
'.fieldLabel('Currency','multicurrency_code').''; - print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); + print ''; + print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); print '
'; + print '
'; if ($soc->outstanding_limit) { - // Outstanding Bill - print ''; - print ''; + // Outstanding Bill + print ''; + print ''; } // Relative and absolute discounts if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final - // invoice + // invoice $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice } else { $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description LIKE '(DEPOSIT)%')"; @@ -2037,7 +2037,7 @@ if ($action == 'create' && $user->rights->commande->creer) } else { print $object->date ? dol_print_date($object->date, 'day') : ' '; if ($object->hasDelay() && ! empty($object->date_livraison)) { - print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); + print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); } } print ''; @@ -2062,51 +2062,51 @@ if ($action == 'create' && $user->rights->commande->creer) } else { print $object->date_livraison ? dol_print_date($object->date_livraison, 'daytext') : ' '; if ($object->hasDelay() && ! empty($object->date_livraison)) { - print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); + print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning"); } } print ''; print ''; - // Shipping Method - if (! empty($conf->expedition->enabled)) { - print ''; - print ''; - } + // Shipping Method + if (! empty($conf->expedition->enabled)) { + print ''; + print ''; + } - // Warehouse - if (! empty($conf->expedition->enabled) && ! empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct=new FormProduct($db); - print ''; - print ''; - } + // Warehouse + if (! empty($conf->expedition->enabled) && ! empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct=new FormProduct($db); + print ''; + print ''; + } // Terms of payment print '
'; - print $langs->trans('OutstandingBill'); - print ''; - print price($soc->get_OutstandingBill()) . ' / '; - print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); - print '
'; + print $langs->trans('OutstandingBill'); + print ''; + print price($soc->get_OutstandingBill()) . ' / '; + print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); + print '
'; - print ''; - if ($action != 'editshippingmethod' && $user->rights->commande->creer) - print ''; - print '
'; - print $langs->trans('SendingMethod'); - print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; - print '
'; - if ($action == 'editshippingmethod') { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); - } else { - $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); - } - print '
'; + print ''; + if ($action != 'editshippingmethod' && $user->rights->commande->creer) + print ''; + print '
'; + print $langs->trans('SendingMethod'); + print 'id.'">'.img_edit($langs->trans('SetShippingMode'),1).'
'; + print '
'; + if ($action == 'editshippingmethod') { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); + } else { + $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none'); + } + print '
'; - print ''; - if ($action != 'editwarehouse' && $user->rights->commande->creer) - print ''; - print '
'; - print $langs->trans('Warehouse'); - print 'id.'">'.img_edit($langs->trans('SetWarehouse'),1).'
'; - print '
'; - if ($action == 'editwarehouse') { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); - } else { - $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); - } - print '
'; + print ''; + if ($action != 'editwarehouse' && $user->rights->commande->creer) + print ''; + print '
'; + print $langs->trans('Warehouse'); + print 'id.'">'.img_edit($langs->trans('SetWarehouse'),1).'
'; + print '
'; + if ($action == 'editwarehouse') { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1); + } else { + $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none'); + } + print '
'; @@ -2173,9 +2173,9 @@ if ($action == 'create' && $user->rights->commande->creer) print '
'; print ''; if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { - if($action == 'actualizemulticurrencyrate') { - list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); - } + if($action == 'actualizemulticurrencyrate') { + list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); + } $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); } else { $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); @@ -2243,30 +2243,30 @@ if ($action == 'create' && $user->rights->commande->creer) $totalVolume=$tmparray['volume']; if ($totalWeight || $totalVolume) { - print ''.$langs->trans("CalculatedWeight").''; - print ''; - print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no'); - print ''; - print ''.$langs->trans("CalculatedVolume").''; - print ''; - print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no'); - print ''; + print ''.$langs->trans("CalculatedWeight").''; + print ''; + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND)?$conf->global->MAIN_WEIGHT_DEFAULT_ROUND:-1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT)?$conf->global->MAIN_WEIGHT_DEFAULT_UNIT:'no'); + print ''; + print ''.$langs->trans("CalculatedVolume").''; + print ''; + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND)?$conf->global->MAIN_VOLUME_DEFAULT_ROUND:-1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT)?$conf->global->MAIN_VOLUME_DEFAULT_UNIT:'no'); + print ''; } - // TODO How record was recorded OrderMode (llx_c_input_method) + // TODO How record was recorded OrderMode (llx_c_input_method) // Incoterms if (!empty($conf->incoterm->enabled)) { print ''; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->commande->creer) print ''.img_edit().''; - else print ' '; - print '
'; - print ''; - print ''; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->commande->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print ''; + print ''; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); @@ -2275,27 +2275,27 @@ if ($action == 'create' && $user->rights->commande->creer) { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id); } - print ''; + print ''; } - // Bank Account + // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && ! empty($conf->banque->enabled)) { - print ''; - print ''; - print '
'; - print $langs->trans('BankAccount'); - print ''; - if ($action != 'editbankaccount' && $user->rights->commande->creer) - print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; - print ''; - if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); - } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); - } - print ''; - print ''; + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if ($action != 'editbankaccount' && $user->rights->commande->creer) + print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print ''; + print ''; } // Other attributes @@ -2312,20 +2312,20 @@ if ($action == 'create' && $user->rights->commande->creer) if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print '' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ''; - print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount HT + print '' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ''; + print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; - // Multicurrency Amount VAT - print '' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ''; - print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount VAT + print '' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ''; + print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; - // Multicurrency Amount TTC - print '' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ''; - print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount TTC + print '' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ''; + print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; } // Total HT @@ -2357,7 +2357,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Margin Infos if (! empty($conf->margin->enabled)) { - $formmargin->displayMarginInfos($object); + $formmargin->displayMarginInfos($object); } @@ -2395,7 +2395,7 @@ if ($action == 'create' && $user->rights->commande->creer) include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } - print '
'; + print '
'; print ''; // Show object lines @@ -2421,7 +2421,7 @@ if ($action == 'create' && $user->rights->commande->creer) } } print '
'; - print '
'; + print '
'; print "\n"; @@ -2435,7 +2435,7 @@ if ($action == 'create' && $user->rights->commande->creer) $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been - // modified by hook + // modified by hook if (empty($reshook)) { // Send if ($object->statut > Commande::STATUS_DRAFT) { @@ -2445,10 +2445,10 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; } - // Valid + // Valid if ($object->statut == Commande::STATUS_DRAFT && $object->total_ttc >= 0 && $numlines > 0 && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) ) { print ''; @@ -2459,8 +2459,8 @@ if ($action == 'create' && $user->rights->commande->creer) } // Create event if ($conf->agenda->enabled && ! empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a - // "workflow" action so should appears somewhere else on - // page. + // "workflow" action so should appears somewhere else on + // page. { print '' . $langs->trans("AddAction") . ''; } @@ -2480,11 +2480,11 @@ if ($action == 'create' && $user->rights->commande->creer) // Create contract if ($conf->contrat->enabled && ($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS || $object->statut == Commande::STATUS_CLOSED)) { - $langs->load("contracts"); + $langs->load("contracts"); - if ($user->rights->contrat->creer) { - print ''; - } + if ($user->rights->contrat->creer) { + print ''; + } } // Ship @@ -2527,9 +2527,9 @@ if ($action == 'create' && $user->rights->commande->creer) } } if ($object->statut > Commande::STATUS_DRAFT && $object->billed) { - if ($user->rights->commande->creer && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { - print ''; - } + if ($user->rights->commande->creer && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { + print ''; + } } // Clone if ($user->rights->commande->creer) { @@ -2538,8 +2538,8 @@ if ($action == 'create' && $user->rights->commande->creer) // Cancel order if ($object->statut == Commande::STATUS_VALIDATED && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->cloturer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->annuler))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->cloturer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->annuler))) ) { print ''; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 55b128bcb6a..53b3cc8880d 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -307,11 +307,11 @@ if (empty($reshook)) $date = dol_mktime(12, 0, 0, $_POST['invoicedatemonth'], $_POST['invoicedateday'], $_POST['invoicedateyear']); if (empty($date)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); - header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id.'&action=editinvoicedate'); - exit; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); + header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id.'&action=editinvoicedate'); + exit; } - $object->date=$date; + $object->date=$date; $new_date_lim_reglement = $object->calculate_date_lim_reglement(); if ($new_date_lim_reglement > $old_date_lim_reglement) $object->date_lim_reglement = $new_date_lim_reglement; if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement = $object->date; @@ -323,7 +323,7 @@ if (empty($reshook)) { $object->fetch($id); $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); - $object->date_pointoftax=$date_pointoftax; + $object->date_pointoftax=$date_pointoftax; $result = $object->update($user); if ($result < 0) dol_print_error($db, $object->error); } @@ -369,14 +369,14 @@ if (empty($reshook)) // Set incoterm elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - } + { + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + } // bank account else if ($action == 'setbankaccount' && $user->rights->facture->creer) { - $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + $result=$object->setBankAccount(GETPOST('fk_account', 'int')); } else if ($action == 'setremisepercent' && $user->rights->facture->creer) @@ -451,8 +451,8 @@ if (empty($reshook)) // Classify to validated else if ($action == 'confirm_valid' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) ) { $idwarehouse = GETPOST('idwarehouse','int'); @@ -462,7 +462,7 @@ if (empty($reshook)) // Check parameters - // Check for mandatory fields defined into setup + // Check for mandatory fields defined into setup $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL'); foreach($array_to_check as $key) { @@ -540,7 +540,7 @@ if (empty($reshook)) $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } } else @@ -554,7 +554,7 @@ if (empty($reshook)) // Go back to draft status (unvalidate) else if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) ) { $idwarehouse = GETPOST('idwarehouse'); @@ -831,7 +831,7 @@ if (empty($reshook)) $object->fk_project = $_POST['projectid']; $object->cond_reglement_id = $_POST['cond_reglement_id']; $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_account = GETPOST('fk_account', 'int'); $object->remise_absolue = $_POST['remise_absolue']; $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); @@ -883,7 +883,7 @@ if (empty($reshook)) $object->fk_project = $_POST['projectid']; $object->cond_reglement_id = 0; $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_account = GETPOST('fk_account', 'int'); $object->remise_absolue = $_POST['remise_absolue']; $object->remise_percent = $_POST['remise_percent']; $object->fk_incoterms = GETPOST('incoterm_id', 'int'); @@ -899,62 +899,62 @@ if (empty($reshook)) if (GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0) { - $facture_source = new Facture($db); // fetch origin object - if ($facture_source->fetch($object->fk_facture_source)>0) - { - $fk_parent_line = 0; + $facture_source = new Facture($db); // fetch origin object + if ($facture_source->fetch($object->fk_facture_source)>0) + { + $fk_parent_line = 0; - foreach($facture_source->lines as $line) - { - // Reset fk_parent_line for no child products and special product - if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { - $fk_parent_line = 0; - } + foreach($facture_source->lines as $line) + { + // Reset fk_parent_line for no child products and special product + if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { + $fk_parent_line = 0; + } - $line->fk_facture = $object->id; - $line->fk_parent_line = $fk_parent_line; + $line->fk_facture = $object->id; + $line->fk_parent_line = $fk_parent_line; - $line->subprice = -$line->subprice; // invert price for object - $line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here - $line->total_ht = -$line->total_ht; - $line->total_tva = -$line->total_tva; - $line->total_ttc = -$line->total_ttc; - $line->total_localtax1 = -$line->total_localtax1; - $line->total_localtax2 = -$line->total_localtax2; + $line->subprice = -$line->subprice; // invert price for object + $line->pa_ht = $line->pa_ht; // we choosed to have buy/cost price always positive, so no revert of sign here + $line->total_ht = -$line->total_ht; + $line->total_tva = -$line->total_tva; + $line->total_ttc = -$line->total_ttc; + $line->total_localtax1 = -$line->total_localtax1; + $line->total_localtax2 = -$line->total_localtax2; - $line->multicurrency_subprice = -$line->multicurrency_subprice; - $line->multicurrency_total_ht = -$line->multicurrency_total_ht; - $line->multicurrency_total_tva = -$line->multicurrency_total_tva; - $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc; + $line->multicurrency_subprice = -$line->multicurrency_subprice; + $line->multicurrency_total_ht = -$line->multicurrency_total_ht; + $line->multicurrency_total_tva = -$line->multicurrency_total_tva; + $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc; - $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked + $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked - $object->lines[] = $line; // insert new line in current object + $object->lines[] = $line; // insert new line in current object - // Defined the new fk_parent_line - if ($result > 0 && $line->product_type == 9) { - $fk_parent_line = $result; - } - } + // Defined the new fk_parent_line + if ($result > 0 && $line->product_type == 9) { + $fk_parent_line = $result; + } + } - $object->update_price(1); - } + $object->update_price(1); + } } - if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) - { - $facture_source = new Facture($db); // fetch origin object if not previously defined - if ($facture_source->fetch($object->fk_facture_source)>0) - { - $totalpaye = $facture_source->getSommePaiement(); - $totalcreditnotes = $facture_source->getSumCreditNotesUsed(); - $totaldeposits = $facture_source->getSumDepositsUsed(); - $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits); + if(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int')==1 && $id>0) + { + $facture_source = new Facture($db); // fetch origin object if not previously defined + if ($facture_source->fetch($object->fk_facture_source)>0) + { + $totalpaye = $facture_source->getSommePaiement(); + $totalcreditnotes = $facture_source->getSumCreditNotesUsed(); + $totaldeposits = $facture_source->getSumDepositsUsed(); + $remain_to_pay = abs($facture_source->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits); - $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,'','','TTC'); - } - } + $object->addline($langs->trans('invoiceAvoirLineWithPaymentRestAmount'),$remain_to_pay,1,0,0,0,0,0,'','','TTC'); + } + } } } @@ -985,7 +985,7 @@ if (empty($reshook)) $object->fk_project = $_POST['projectid']; $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']); $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_account = GETPOST('fk_account', 'int'); $object->amount = $_POST['amount']; $object->remise_absolue = $_POST['remise_absolue']; $object->remise_percent = $_POST['remise_percent']; @@ -1035,7 +1035,7 @@ if (empty($reshook)) $object->fk_project = $_POST['projectid']; $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']); $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->fk_account = GETPOST('fk_account', 'int'); + $object->fk_account = GETPOST('fk_account', 'int'); $object->amount = $_POST['amount']; $object->remise_absolue = $_POST['remise_absolue']; $object->remise_percent = $_POST['remise_percent']; @@ -1117,7 +1117,7 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines or deposit lines"); $result = $srcobject->fetch($object->origin_id); - // If deposit invoice + // If deposit invoice if ($_POST['type'] == Facture::TYPE_DEPOSIT) { $typeamount = GETPOST('typedeposit', 'alpha'); @@ -1167,8 +1167,8 @@ if (empty($reshook)) if ($totalamount != 0) { if ($numlines > 0) $numlines = $numlines-1; - $tva_tx = $lines[$numlines]->tva_tx; - if (! empty($lines[$numlines]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$numlines]->vat_src_code.')'; + $tva_tx = $lines[$numlines]->tva_tx; + if (! empty($lines[$numlines]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$numlines]->vat_src_code.')'; $amountdeposit[$tva_tx] = ($totalamount * $valuedeposit) / 100; } else { $amountdeposit[0] = 0; @@ -1205,7 +1205,7 @@ if (empty($reshook)) 0, // date_start 0, // date_end 0, - $lines[$i]->info_bits, // info_bits + $lines[$i]->info_bits, // info_bits 0, 'HT', 0, @@ -1367,8 +1367,8 @@ if (empty($reshook)) // modified by hook if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - $error++; + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + $error++; } } else { @@ -1540,16 +1540,16 @@ if (empty($reshook)) setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error ++; } - if (!$prod_entry_mode) - { - if (GETPOST('type') < 0 && ! GETPOST('search_idprod')) - { - setEventMessages($langs->trans('ErrorChooseBetweenFreeEntryOrPredefinedProduct'), null, 'errors'); - $error ++; - } - } + if (!$prod_entry_mode) + { + if (GETPOST('type') < 0 && ! GETPOST('search_idprod')) + { + setEventMessages($langs->trans('ErrorChooseBetweenFreeEntryOrPredefinedProduct'), null, 'errors'); + $error ++; + } + } if ($prod_entry_mode == 'free' && empty($idprod) && GETPOST('type') < 0) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); $error ++; } if ($prod_entry_mode == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '') && $price_ht_devise == '') // Unit price can be 0 but not '' @@ -1634,8 +1634,8 @@ if (empty($reshook)) $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility { - if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; - if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; + if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; if (empty($tva_tx)) $tva_npr=0; } } @@ -1790,18 +1790,18 @@ if (empty($reshook)) unset($_POST['idprod']); unset($_POST['units']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); unset($_POST['situations']); unset($_POST['progress']); @@ -1966,18 +1966,18 @@ if (empty($reshook)) unset($_POST['idprod']); unset($_POST['units']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); unset($_POST['situations']); unset($_POST['progress']); @@ -2020,10 +2020,10 @@ if (empty($reshook)) $trackid='inv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - // Actions to build doc - $upload_dir = $conf->facture->dir_output; - $permissioncreate=$user->rights->facture->creer; - include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; + // Actions to build doc + $upload_dir = $conf->facture->dir_output; + $permissioncreate=$user->rights->facture->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; if ($action == 'update_extras') { @@ -2195,7 +2195,7 @@ if ($action == 'create') $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); + $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0)); $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice); @@ -2238,14 +2238,14 @@ if ($action == 'create') if ($origin == 'contrat') { - $langs->load("admin"); - $text=$langs->trans("ToCreateARecurringInvoice"); - $text.=' '.$langs->trans("ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv("MenuFinancial"), $langs->transnoentitiesnoconv("BillsCustomers"), $langs->transnoentitiesnoconv("ListOfTemplates")); - if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) - { - $text.=' '.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')); - } - print info_admin($text, 0, 0, 0).'
'; + $langs->load("admin"); + $text=$langs->trans("ToCreateARecurringInvoice"); + $text.=' '.$langs->trans("ToCreateARecurringInvoiceGene", $langs->transnoentitiesnoconv("MenuFinancial"), $langs->transnoentitiesnoconv("BillsCustomers"), $langs->transnoentitiesnoconv("ListOfTemplates")); + if (empty($conf->global->INVOICE_DISABLE_AUTOMATIC_RECURRING_INVOICE)) + { + $text.=' '.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')); + } + print info_admin($text, 0, 0, 0).'
'; } print '
'; @@ -2303,7 +2303,7 @@ if ($action == 'create') }); '; } - print ' '.$langs->trans("AddThirdParty").''; + print ' '.$langs->trans("AddThirdParty").''; print ''; } print '' . "\n"; @@ -2313,16 +2313,16 @@ if ($action == 'create') // Overwrite value if creation of invoice is from a predefined invoice if (empty($origin) && empty($originid) && GETPOST('fac_rec','int') > 0) { - $invoice_predefined = new FactureRec($db); - $invoice_predefined->fetch(GETPOST('fac_rec','int')); + $invoice_predefined = new FactureRec($db); + $invoice_predefined->fetch(GETPOST('fac_rec','int')); - $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later - if (empty($projectid)) $projectid = $invoice_predefined->fk_project; - $cond_reglement_id = $invoice_predefined->cond_reglement_id; - $mode_reglement_id = $invoice_predefined->mode_reglement_id; - $fk_account = $invoice_predefined->fk_account; - $note_public = $invoice_predefined->note_public; - $note_private = $invoice_predefined->note_private; + $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later + if (empty($projectid)) $projectid = $invoice_predefined->fk_project; + $cond_reglement_id = $invoice_predefined->cond_reglement_id; + $mode_reglement_id = $invoice_predefined->mode_reglement_id; + $fk_account = $invoice_predefined->fk_account; + $note_public = $invoice_predefined->note_public; + $note_private = $invoice_predefined->note_private; $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r'; @@ -2345,17 +2345,17 @@ if ($action == 'create') print ''; $i ++; } print ''; // Option to reload page to retrieve customer informations. Note, this clear other input - if (!empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE)) - { - print ''; - } + } print ''; } $db->free($resql); @@ -2433,9 +2433,9 @@ if ($action == 'create') // Deposit if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) { - print '
'; - $tmp=' '; - print ''; - $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); - print ''; - if (($origin == 'propal') || ($origin == 'commande')) - { - print ''; - print '
'; - print $desc; - print ''; - $arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount'); - print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); - print '' . $langs->trans('Value') . ':'; - } - print '
'; + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); + print ''; + if (($origin == 'propal') || ($origin == 'commande')) + { + print ''; + print '
'; + print $desc; + print ''; + $arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount'); + print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); + print '' . $langs->trans('Value') . ':'; + } + print '
'; - print '
'; + print '
'; } } @@ -2490,33 +2490,33 @@ if ($action == 'create') // Replacement if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { - print ''; - print '
'; - $tmp=' + print ''; + print '
'; + $tmp=' jQuery(document).ready(function() { jQuery("#fac_replacement").change(function() { jQuery("#radio_replacement").prop("checked", true); }); }); '; - $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); - print $desc; - print '
'; + $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; } } else @@ -2534,15 +2534,15 @@ if ($action == 'create') { if ($socid > 0) { - // Credit note - if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) - { - print '
'; - $tmp=' + // Credit note + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) + { + print '
'; + $tmp=' jQuery(document).ready(function() { if (! jQuery("#radio_creditnote").is(":checked")) { @@ -2556,29 +2556,29 @@ if ($action == 'create') }); }); '; - $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; - // $text.=''; - $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); - print $desc; + $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; + // $text.=''; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); + print $desc; - print '
'; - print '    0 ? 'checked':'').' /> "; - print '
    0 ? 'checked':'').' /> "; - print '
'; + print '
'; + print '    0 ? 'checked':'').' /> "; + print '
    0 ? 'checked':'').' /> "; + print '
'; - print '
'; - } + print '
'; + } } else { @@ -2652,14 +2652,14 @@ if ($action == 'create') $form->select_types_paiements(isset($_POST['mode_reglement_id']) ? $_POST['mode_reglement_id'] : $mode_reglement_id, 'mode_reglement_id', 'CRDT'); print ''; - // Bank Account + // Bank Account if (isset($_POST['fk_account'])) { $fk_account = $_POST['fk_account']; } - print '' . $langs->trans('BankAccount') . ''; - $form->select_comptes($fk_account, 'fk_account', 0, '', 1); - print ''; + print '' . $langs->trans('BankAccount') . ''; + $form->select_comptes($fk_account, 'fk_account', 0, '', 1); + print ''; // Project if (! empty($conf->projet->enabled) && $socid > 0) @@ -2676,22 +2676,22 @@ if ($action == 'create') { print ''; print ''; - print ''; - $incoterm_id = GETPOST('incoterm_id'); - $incoterm_location = GETPOST('location_incoterms'); - if (empty($incoterm_id)) - { - $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); - $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); - } - print $form->select_incoterms($incoterm_id, $incoterm_location); + print ''; + $incoterm_id = GETPOST('incoterm_id'); + $incoterm_location = GETPOST('location_incoterms'); + if (empty($incoterm_id)) + { + $incoterm_id = (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : $soc->fk_incoterms); + $incoterm_location = (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : $soc->location_incoterms); + } + print $form->select_incoterms($incoterm_id, $incoterm_location); print ''; } // Other attributes $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="2"', 'cols'=>2); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } @@ -2709,8 +2709,8 @@ if ($action == 'create') { print ''; print ''.fieldLabel('Currency','multicurrency_code').''; - print ''; - print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); + print ''; + print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); print ''; } @@ -2718,28 +2718,28 @@ if ($action == 'create') $htmltext=''; if (GETPOST('fac_rec','int') > 0) { - $dateexample=($datefacture ? $datefacture : $dateinvoice); - if (empty($dateexample)) $dateexample=dol_now(); - $substitutionarray=array( - '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')', - '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')', - '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%m').')', - '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%m').')', - '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'),'%m').')', - '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%B').')', - '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%B').')', - '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')', - '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'),'%Y').')', - '__INVOICE_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%Y').')', - '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'),'%Y').')' - ); + $dateexample=($datefacture ? $datefacture : $dateinvoice); + if (empty($dateexample)) $dateexample=dol_now(); + $substitutionarray=array( + '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')', + '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')', + '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%m').')', + '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%m').')', + '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'),'%m').')', + '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'),'%B').')', + '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%B').')', + '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')', + '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'),'%Y').')', + '__INVOICE_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample,'%Y').')', + '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'),'%Y').')' + ); - $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; - foreach($substitutionarray as $key => $val) - { - $htmltext.=$key.' = '.$langs->trans($val).'
'; - } - $htmltext.='
'; + $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; + foreach($substitutionarray as $key => $val) + { + $htmltext.=$key.' = '.$langs->trans($val).'
'; + } + $htmltext.='
'; } // Public note @@ -2810,8 +2810,8 @@ if ($action == 'create') $cntinvoice=count($objectsrc->linkedObjects['facture']); if ($cntinvoice>=1) { - setEventMessages('WarningBillExist', null, 'warnings'); - echo ' ('.$langs->trans('LatestRelatedBill').end($objectsrc->linkedObjects['facture'])->getNomUrl(1).')'; + setEventMessages('WarningBillExist', null, 'warnings'); + echo ' ('.$langs->trans('LatestRelatedBill').end($objectsrc->linkedObjects['facture'])->getNomUrl(1).')'; } echo ''; print '' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . ''; @@ -3179,34 +3179,34 @@ else if ($id > 0 || ! empty($ref)) // Project if (! empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.=''; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } } $morehtmlref.='
'; @@ -3259,7 +3259,7 @@ else if ($id > 0 || ! empty($ref)) $discount = new DiscountAbsolute($db); $result = $discount->fetch(0, $object->id); if ($result > 0){ - print '. '.$langs->trans("CreditNoteConvertedIntoDiscount", $object->getLibType(), $discount->getNomUrl(1, 'discount')).'
'; + print '. '.$langs->trans("CreditNoteConvertedIntoDiscount", $object->getLibType(), $discount->getNomUrl(1, 'discount')).'
'; } } print ''; @@ -3501,16 +3501,16 @@ else if ($id > 0 || ! empty($ref)) print $langs->trans('BankAccount'); print ''; if (($action != 'editbankaccount') && $user->rights->facture->creer && ! empty($object->brouillon)) - print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).''; + print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).''; print ''; print ''; if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } print ""; print ''; @@ -3568,14 +3568,14 @@ else if ($id > 0 || ! empty($ref)) if (!empty($conf->incoterm->enabled)) { print ''; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->facture->creer) print ''.img_edit().''; - else print ' '; - print '
'; - print ''; - print ''; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->facture->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print ''; + print ''; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); @@ -3584,7 +3584,7 @@ else if ($id > 0 || ! empty($ref)) { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms)?$object->location_incoterms:''), $_SERVER['PHP_SELF'].'?id='.$object->id); } - print ''; + print ''; } // Other attributes @@ -3602,20 +3602,20 @@ else if ($id > 0 || ! empty($ref)) if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print '' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ''; - print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount HT + print '' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ''; + print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; - // Multicurrency Amount VAT - print '' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ''; - print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount VAT + print '' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ''; + print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; - // Multicurrency Amount TTC - print '' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ''; - print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; - print ''; + // Multicurrency Amount TTC + print '' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ''; + print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; + print ''; } // Amount @@ -3629,40 +3629,40 @@ else if ($id > 0 || ! empty($ref)) // Amount Local Taxes if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) // Localtax1 { - print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ''; - print '' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . ''; + print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ''; + print '' . price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency) . ''; } if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) // Localtax2 { - print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ''; - print '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . ''; + print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ''; + print '' . price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency) . ''; } // Revenue stamp if ($selleruserevenustamp) // Test company use revenue stamp { - print ''; - print ''; - if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer) - { - print ''; - } - print '
'; - print $langs->trans('RevenueStamp'); - print 'id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '
'; - print ''; - if ($action == 'editrevenuestamp') { - print '
'; - print ''; - print ''; - print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code); - // print ''; - print ' '; - print '
'; - } else { - print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency); - } - print ''; + print ''; + print ''; + if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer) + { + print ''; + } + print '
'; + print $langs->trans('RevenueStamp'); + print 'id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '
'; + print ''; + if ($action == 'editrevenuestamp') { + print '
'; + print ''; + print ''; + print $formother->select_revenue_stamp(GETPOST('revenuestamp'), 'revenuestamp', $mysoc->country_code); + // print ''; + print ' '; + print '
'; + } else { + print price($object->revenuestamp, 1, '', 1, - 1, - 1, $conf->currency); + } + print ''; } // Total with tax @@ -3675,165 +3675,165 @@ else if ($id > 0 || ! empty($ref)) $sign = 1; if ($object->type == Facture::TYPE_CREDIT_NOTE) $sign = - 1; - $nbrows = 8; - $nbcols = 3; - if (! empty($conf->projet->enabled)) - $nbrows ++; - if (! empty($conf->banque->enabled)) { - $nbrows ++; - $nbcols ++; - } - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) - $nbrows ++; - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) - $nbrows ++; - if ($selleruserevenustamp) - $nbrows ++; - if (! empty($conf->multicurrency->enabled)) - $nbrows += 5; - if (! empty($conf->incoterm->enabled)) - $nbrows += 1; + $nbrows = 8; + $nbcols = 3; + if (! empty($conf->projet->enabled)) + $nbrows ++; + if (! empty($conf->banque->enabled)) { + $nbrows ++; + $nbcols ++; + } + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) + $nbrows ++; + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) + $nbrows ++; + if ($selleruserevenustamp) + $nbrows ++; + if (! empty($conf->multicurrency->enabled)) + $nbrows += 5; + if (! empty($conf->incoterm->enabled)) + $nbrows += 1; - if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) - { - if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) - print ''; + if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) + { + if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) + print '
'; - if (count($object->tab_previous_situation_invoice) > 0) { - // List of previous invoices - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; + if (count($object->tab_previous_situation_invoice) > 0) { + // List of previous invoices + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + print ''; - $total_prev_ht = $total_prev_ttc = 0; - foreach ($object->tab_previous_situation_invoice as $prev_invoice) { - $totalpaye = $prev_invoice->getSommePaiement(); - $total_prev_ht += $prev_invoice->total_ht; - $total_prev_ttc += $prev_invoice->total_ttc; - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; + $total_prev_ht = $total_prev_ttc = 0; + foreach ($object->tab_previous_situation_invoice as $prev_invoice) { + $totalpaye = $prev_invoice->getSommePaiement(); + $total_prev_ht += $prev_invoice->total_ht; + $total_prev_ttc += $prev_invoice->total_ttc; + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + print ''; - } + } - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + print ''; + } - if (count($object->tab_next_situation_invoice) > 0) { - // List of next invoices - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; + if (count($object->tab_next_situation_invoice) > 0) { + // List of next invoices + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + print ''; - $total_next_ht = $total_next_ttc = 0; + $total_next_ht = $total_next_ttc = 0; - foreach ($object->tab_next_situation_invoice as $next_invoice) { - $totalpaye = $next_invoice->getSommePaiement(); - $total_next_ht += $next_invoice->total_ht; - $total_next_ttc += $next_invoice->total_ttc; - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; + foreach ($object->tab_next_situation_invoice as $next_invoice) { + $totalpaye = $next_invoice->getSommePaiement(); + $total_next_ht += $next_invoice->total_ht; + $total_next_ttc += $next_invoice->total_ttc; + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + print ''; - } + } - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; + print ''; + } - if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) - print '
' . $langs->trans('ListOfPreviousSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
' . $langs->trans('ListOfPreviousSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
' . $prev_invoice->getNomUrl(1) . '' . price($prev_invoice->total_ht) . '' . price($prev_invoice->total_ttc) . '' . $prev_invoice->getLibStatut(3, $totalpaye) . '
' . $prev_invoice->getNomUrl(1) . '' . price($prev_invoice->total_ht) . '' . price($prev_invoice->total_ttc) . '' . $prev_invoice->getLibStatut(3, $totalpaye) . '
' . price($total_prev_ht) . '' . price($total_prev_ttc) . ' 
' . price($total_prev_ht) . '' . price($total_prev_ttc) . ' 
' . $langs->trans('ListOfNextSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
' . $langs->trans('ListOfNextSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
' . $next_invoice->getNomUrl(1) . '' . price($next_invoice->total_ht) . '' . price($next_invoice->total_ttc) . '' . $next_invoice->getLibStatut(3, $totalpaye) . '
' . $next_invoice->getNomUrl(1) . '' . price($next_invoice->total_ht) . '' . price($next_invoice->total_ttc) . '' . $next_invoice->getLibStatut(3, $totalpaye) . '
' . price($total_next_ht) . '' . price($total_next_ttc) . ' 
' . price($total_next_ht) . '' . price($total_next_ttc) . ' 
'; - } + if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) + print ''; + } - // List of payments already done + // List of payments already done - print ''; + print '
'; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) { - print ''; - } - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) { + print ''; + } + print ''; + print ''; + print ''; - // Payments already done (from payment on this invoice) - $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,'; - $sql .= ' c.code as payment_code, c.libelle as payment_label,'; - $sql .= ' pf.amount,'; - $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p'; - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; - $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; - $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; - $sql .= ' AND c.entity IN (' . getEntity('c_paiement').')'; - $sql .= ' ORDER BY p.datep, p.tms'; + // Payments already done (from payment on this invoice) + $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement, p.rowid, p.fk_bank,'; + $sql .= ' c.code as payment_code, c.libelle as payment_label,'; + $sql .= ' pf.amount,'; + $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p'; + $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid'; + $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid'; + $sql .= ' WHERE pf.fk_facture = ' . $object->id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid'; + $sql .= ' AND c.entity IN (' . getEntity('c_paiement').')'; + $sql .= ' ORDER BY p.datep, p.tms'; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; - // if ($object->type != 2) - // { - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); + // if ($object->type != 2) + // { + if ($num > 0) { + while ($i < $num) { + $objp = $db->fetch_object($result); - $paymentstatic->id = $objp->rowid; - $paymentstatic->datepaye = $db->jdate($objp->dp); - $paymentstatic->ref = $objp->ref; - $paymentstatic->num_paiement = $objp->num_paiement; - $paymentstatic->payment_code = $objp->payment_code; + $paymentstatic->id = $objp->rowid; + $paymentstatic->datepaye = $db->jdate($objp->dp); + $paymentstatic->ref = $objp->ref; + $paymentstatic->num_paiement = $objp->num_paiement; + $paymentstatic->payment_code = $objp->payment_code; - print ''; - print ''; - $label = ($langs->trans("PaymentType" . $objp->payment_code) != ("PaymentType" . $objp->payment_code)) ? $langs->trans("PaymentType" . $objp->payment_code) : $objp->payment_label; - print ''; - if (! empty($conf->banque->enabled)) - { - $bankaccountstatic->id = $objp->baid; - $bankaccountstatic->ref = $objp->baref; - $bankaccountstatic->label = $objp->baref; + print ''; + print ''; + $label = ($langs->trans("PaymentType" . $objp->payment_code) != ("PaymentType" . $objp->payment_code)) ? $langs->trans("PaymentType" . $objp->payment_code) : $objp->payment_label; + print ''; + if (! empty($conf->banque->enabled)) + { + $bankaccountstatic->id = $objp->baid; + $bankaccountstatic->ref = $objp->baref; + $bankaccountstatic->label = $objp->baref; $bankaccountstatic->number = $objp->banumber; if (! empty($conf->accounting->enabled)) { @@ -3845,155 +3845,155 @@ else if ($id > 0 || ! empty($ref)) } print ''; - } - print ''; - print ''; - print ''; - $i ++; - } - } - /*else { + if ($bankaccountstatic->id) + print $bankaccountstatic->getNomUrl(1, 'transactions'); + print ''; + } + print ''; + print ''; + print ''; + $i ++; + } + } + /*else { print ''; }*/ - // } - $db->free($result); - } else { - dol_print_error($db); - } + // } + $db->free($result); + } else { + dol_print_error($db); + } - if ($object->type != Facture::TYPE_CREDIT_NOTE) { - // Total already paid - print ''; + if ($object->type != Facture::TYPE_CREDIT_NOTE) { + // Total already paid + print ''; - $resteapayeraffiche = $resteapayer; - $cssforamountpaymentcomplete = 'amountpaymentcomplete'; + $resteapayeraffiche = $resteapayer; + $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - // Loop on each credit note or deposit amount applied - $creditnoteamount = 0; - $depositamount = 0; - $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; - $sql .= " re.description, re.fk_facture_source"; - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; - $sql .= " WHERE fk_facture = " . $object->id; - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - $invoice = new Facture($db); - while ($i < $num) { - $obj = $db->fetch_object($resql); - $invoice->fetch($obj->fk_facture_source); - print ''; - print ''; - print ''; - $i ++; - if ($invoice->type == Facture::TYPE_CREDIT_NOTE) - $creditnoteamount += $obj->amount_ttc; - if ($invoice->type == Facture::TYPE_DEPOSIT) - $depositamount += $obj->amount_ttc; - } - } else { - dol_print_error($db); - } + // Loop on each credit note or deposit amount applied + $creditnoteamount = 0; + $depositamount = 0; + $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; + $sql .= " re.description, re.fk_facture_source"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; + $sql .= " WHERE fk_facture = " . $object->id; + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + $invoice = new Facture($db); + while ($i < $num) { + $obj = $db->fetch_object($resql); + $invoice->fetch($obj->fk_facture_source); + print ''; + print ''; + print ''; + $i ++; + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) + $creditnoteamount += $obj->amount_ttc; + if ($invoice->type == Facture::TYPE_DEPOSIT) + $depositamount += $obj->amount_ttc; + } + } else { + dol_print_error($db); + } - // Paye partiellement 'escompte' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = ''; - } - // Paye partiellement ou Abandon 'badcustomer' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'badcustomer') { - print ''; - // $resteapayeraffiche=0; - $cssforamountpaymentcomplete = ''; - } - // Paye partiellement ou Abandon 'product_returned' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'product_returned') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = ''; - } - // Paye partiellement ou Abandon 'abandon' - if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'abandon') { - print ''; - $resteapayeraffiche = 0; - $cssforamountpaymentcomplete = ''; - } + // Paye partiellement 'escompte' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'discount_vat') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'badcustomer' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'badcustomer') { + print ''; + // $resteapayeraffiche=0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'product_returned' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'product_returned') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } + // Paye partiellement ou Abandon 'abandon' + if (($object->statut == Facture::STATUS_CLOSED || $object->statut == Facture::STATUS_ABANDONED) && $object->close_code == 'abandon') { + print ''; + $resteapayeraffiche = 0; + $cssforamountpaymentcomplete = ''; + } - // Billed - print ''; + // Billed + print ''; - // Remainder to pay - print ''; - print ''; - print ''; - } - else // Credit note - { - $cssforamountpaymentcomplete=''; + // Remainder to pay + print ''; + print ''; + print ''; + } + else // Credit note + { + $cssforamountpaymentcomplete=''; - // Total already paid back - print ''; + // Total already paid back + print ''; - // Billed - print ''; + // Billed + print ''; - // Remainder to pay back - print ''; - print ''; - print ''; + // Remainder to pay back + print ''; + print ''; + print ''; - // Sold credit note - // print ''; - // print ''; - } + // Sold credit note + // print ''; + // print ''; + } - print '
' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '' . $langs->trans('Date') . '' . $langs->trans('Type') . '' . $langs->trans('BankAccount') . '' . $langs->trans('Amount') . ' 
' . ($object->type == Facture::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')) . '' . $langs->trans('Date') . '' . $langs->trans('Type') . '' . $langs->trans('BankAccount') . '' . $langs->trans('Amount') . ' 
'; - print $paymentstatic->getNomUrl(1); - print '' . dol_print_date($db->jdate($objp->dp), 'day') . '' . $label . ' ' . $objp->num_paiement . '
'; + print $paymentstatic->getNomUrl(1); + print '' . dol_print_date($db->jdate($objp->dp), 'day') . '' . $label . ' ' . $objp->num_paiement . ''; - if ($bankaccountstatic->id) - print $bankaccountstatic->getNomUrl(1, 'transactions'); - print '' . price($sign * $objp->amount) . ' 
' . price($sign * $objp->amount) . ' 
' . $langs->trans("None") . '
'; - if ($object->type != Facture::TYPE_DEPOSIT) - print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); - else - print $langs->trans('AlreadyPaid'); - print ' : 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . ' 
'; + if ($object->type != Facture::TYPE_DEPOSIT) + print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits'); + else + print $langs->trans('AlreadyPaid'); + print ' : 0)?' class="amountalreadypaid"':'').'>' . price($totalpaye) . ' 
'; - if ($invoice->type == Facture::TYPE_CREDIT_NOTE) - print $langs->trans("CreditNote") . ' '; - if ($invoice->type == Facture::TYPE_DEPOSIT) - print $langs->trans("Deposit") . ' '; - print $invoice->getNomUrl(0); - print ' :' . price($obj->amount_ttc) . ''; - print 'rowid . '">' . img_delete() . ''; - print '
'; + if ($invoice->type == Facture::TYPE_CREDIT_NOTE) + print $langs->trans("CreditNote") . ' '; + if ($invoice->type == Facture::TYPE_DEPOSIT) + print $langs->trans("Deposit") . ' '; + print $invoice->getNomUrl(0); + print ' :' . price($obj->amount_ttc) . ''; + print 'rowid . '">' . img_delete() . ''; + print '
'; - print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1); - print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; - print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1); - print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; - print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1); - print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; - $text = $langs->trans("HelpAbandonOther"); - if ($object->close_note) - $text .= '

' . $langs->trans("Reason") . ':' . $object->close_note; - print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1); - print '
' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + print $form->textwithpicto($langs->trans("Discount") . ':', $langs->trans("HelpEscompte"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $langs->trans("HelpAbandonBadCustomer"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + print $form->textwithpicto($langs->trans("ProductReturned") . ':', $langs->trans("HelpAbandonProductReturned"), - 1); + print '' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
'; + $text = $langs->trans("HelpAbandonOther"); + if ($object->close_note) + $text .= '

' . $langs->trans("Reason") . ':' . $object->close_note; + print $form->textwithpicto($langs->trans("Abandoned") . ':', $text, - 1); + print '
' . price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
'; - if ($resteapayeraffiche >= 0) - print $langs->trans('RemainderToPay'); - else - print $langs->trans('ExcessReceived'); - print ' :' . price($resteapayeraffiche) . ' 
'; + if ($resteapayeraffiche >= 0) + print $langs->trans('RemainderToPay'); + else + print $langs->trans('ExcessReceived'); + print ' :' . price($resteapayeraffiche) . ' 
'; - print $langs->trans('AlreadyPaidBack'); - print ' :' . price($sign * $totalpaye) . ' 
'; + print $langs->trans('AlreadyPaidBack'); + print ' :' . price($sign * $totalpaye) . ' 
' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' 
' . $langs->trans("Billed") . ' :' . price($sign * $object->total_ttc) . ' 
'; - if ($resteapayeraffiche <= 0) - print $langs->trans('RemainderToPayBack'); - else - print $langs->trans('ExcessPaydBack'); - print ' :' . price($sign * $resteapayeraffiche) . ' 
'; + if ($resteapayeraffiche <= 0) + print $langs->trans('RemainderToPayBack'); + else + print $langs->trans('ExcessPaydBack'); + print ' :' . price($sign * $resteapayeraffiche) . ' 
'.$langs->trans('TotalTTC').' :'.price($sign * - // $object->total_ttc).' 
'.$langs->trans('TotalTTC').' :'.price($sign * + // $object->total_ttc).' 
'; + print ''; // Margin Infos if (! empty($conf->margin->enabled)) { - $formmargin->displayMarginInfos($object); + $formmargin->displayMarginInfos($object); } print ''; @@ -4084,7 +4084,7 @@ else if ($id > 0 || ! empty($ref)) '; if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { - include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; + include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } print '
'; @@ -4110,7 +4110,7 @@ else if ($id > 0 || ! empty($ref)) } print "\n"; - print "
"; + print ""; print "\n"; @@ -4138,8 +4138,8 @@ else if ($id > 0 || ! empty($ref)) { if (! $objectidnext && $object->is_last_in_cycle()) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) { print ''; } else { @@ -4166,7 +4166,7 @@ else if ($id > 0 || ! empty($ref)) || ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id)) || ($object->type == Facture::TYPE_DEPOSIT && empty($discount->id))) && ($object->statut == 2 || $object->statut == 3 || ($object->statut == 1 && $object->paye == 1)) // Condition ($object->statut == 1 && $object->paye == 1) should not happened but can be found due to corrupted data - && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->invoice_advance->reopen))) // A paid invoice (partially or completely) + && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->invoice_advance->reopen))) // A paid invoice (partially or completely) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { @@ -4179,7 +4179,7 @@ else if ($id > 0 || ! empty($ref)) // Validate if ($object->statut == Facture::STATUS_DRAFT && count($object->lines) > 0 && ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) { print ''; } @@ -4200,22 +4200,22 @@ else if ($id > 0 || ! empty($ref)) // Request a direct debit order if ($object->statut > Facture::STATUS_DRAFT && $object->paye == 0 && $num == 0) { - if ($resteapayer > 0) - { - if ($user->rights->prelevement->bons->creer) - { - $langs->load("withdrawals"); - print ''.$langs->trans("MakeWithdrawRequest").''; - } - else - { - //print ''.$langs->trans("MakeWithdrawRequest").''; - } - } - else - { - //print ''.$langs->trans("MakeWithdrawRequest").''; - } + if ($resteapayer > 0) + { + if ($user->rights->prelevement->bons->creer) + { + $langs->load("withdrawals"); + print ''.$langs->trans("MakeWithdrawRequest").''; + } + else + { + //print ''.$langs->trans("MakeWithdrawRequest").''; + } + } + else + { + //print ''.$langs->trans("MakeWithdrawRequest").''; + } } // Create payment diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index deffb252d9c..fbdabad8fa0 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -34,8 +34,8 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; - //require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; + require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; + //require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; } require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; @@ -129,526 +129,526 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if (GETPOST('cancel','alpha')) $action=''; + if (GETPOST('cancel','alpha')) $action=''; - // Selection of new fields - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - // Set note - include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + // Set note + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once - include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once - include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once + include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once - // Do we click on purge search criteria ? - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers - { - $search_ref=''; - $search_societe=''; - $search_montant_ht=''; - $search_montant_vat=''; - $search_montant_ttc=''; - $search_montant_mode=''; - $search_montant_term=''; - $day=''; - $year=''; - $month=''; - $day_date_when=''; - $year_date_when=''; - $month_date_when=''; - $search_recurring=''; - $search_frequency=''; - $search_unit_frequency=''; - $search_array_options=array(); - } + // Do we click on purge search criteria ? + if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers + { + $search_ref=''; + $search_societe=''; + $search_montant_ht=''; + $search_montant_vat=''; + $search_montant_ttc=''; + $search_montant_mode=''; + $search_montant_term=''; + $day=''; + $year=''; + $month=''; + $day_date_when=''; + $year_date_when=''; + $month_date_when=''; + $search_recurring=''; + $search_frequency=''; + $search_unit_frequency=''; + $search_array_options=array(); + } - // Mass actions - /*$objectclass='MyObject'; + // Mass actions + /*$objectclass='MyObject'; $objectlabel='MyObject'; $permtoread = $user->rights->mymodule->read; $permtodelete = $user->rights->mymodule->delete; $uploaddir = $conf->mymodule->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/ - // Create predefined invoice - if ($action == 'add') - { - if (! GETPOST('titre')) - { - setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors'); - $action = "create"; - $error++; - } + // Create predefined invoice + if ($action == 'add') + { + if (! GETPOST('titre')) + { + setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors'); + $action = "create"; + $error++; + } - $frequency=GETPOST('frequency', 'int'); - $reyear=GETPOST('reyear'); - $remonth=GETPOST('remonth'); - $reday=GETPOST('reday'); - $rehour=GETPOST('rehour'); - $remin=GETPOST('remin'); - $nb_gen_max=GETPOST('nb_gen_max', 'int'); - //if (empty($nb_gen_max)) $nb_gen_max =0; + $frequency=GETPOST('frequency', 'int'); + $reyear=GETPOST('reyear'); + $remonth=GETPOST('remonth'); + $reday=GETPOST('reday'); + $rehour=GETPOST('rehour'); + $remin=GETPOST('remin'); + $nb_gen_max=GETPOST('nb_gen_max', 'int'); + //if (empty($nb_gen_max)) $nb_gen_max =0; - if (GETPOST('frequency')) - { - if (empty($reyear) || empty($remonth) || empty($reday)) - { - setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Date")), null, 'errors'); - $action = "create"; - $error++; - } - if ($nb_gen_max === '') - { - setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors'); - $action = "create"; - $error++; - } - } + if (GETPOST('frequency')) + { + if (empty($reyear) || empty($remonth) || empty($reday)) + { + setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Date")), null, 'errors'); + $action = "create"; + $error++; + } + if ($nb_gen_max === '') + { + setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors'); + $action = "create"; + $error++; + } + } - if (! $error) - { - $object->titre = GETPOST('titre', 'alpha'); - $object->note_private = GETPOST('note_private','none'); - $object->note_public = GETPOST('note_public','none'); - $object->usenewprice = GETPOST('usenewprice'); + if (! $error) + { + $object->titre = GETPOST('titre', 'alpha'); + $object->note_private = GETPOST('note_private','none'); + $object->note_public = GETPOST('note_public','none'); + $object->usenewprice = GETPOST('usenewprice'); - $object->frequency = $frequency; - $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); - $object->nb_gen_max = $nb_gen_max; - $object->auto_validate = GETPOST('auto_validate', 'int'); + $object->frequency = $frequency; + $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); + $object->nb_gen_max = $nb_gen_max; + $object->auto_validate = GETPOST('auto_validate', 'int'); - $object->fk_project = $projectid; + $object->fk_project = $projectid; - $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); - $object->date_when = $date_next_execution; + $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); + $object->date_when = $date_next_execution; - // Get first contract linked to invoice used to generate template - if ($id > 0) - { - $srcObject = new Facture($db); - $srcObject->fetch(GETPOST('facid','int')); + // Get first contract linked to invoice used to generate template + if ($id > 0) + { + $srcObject = new Facture($db); + $srcObject->fetch(GETPOST('facid','int')); - $srcObject->fetchObjectLinked(); + $srcObject->fetchObjectLinked(); - if (! empty($srcObject->linkedObjectsIds['contrat'])) - { - $contractidid = reset($srcObject->linkedObjectsIds['contrat']); + if (! empty($srcObject->linkedObjectsIds['contrat'])) + { + $contractidid = reset($srcObject->linkedObjectsIds['contrat']); - $object->origin = 'contrat'; - $object->origin_id = $contractidid; - $object->linked_objects[$object->origin] = $object->origin_id; - } - } + $object->origin = 'contrat'; + $object->origin_id = $contractidid; + $object->linked_objects[$object->origin] = $object->origin_id; + } + } - $db->begin(); + $db->begin(); - $oldinvoice = new Facture($db); - $oldinvoice->fetch($id); + $oldinvoice = new Facture($db); + $oldinvoice->fetch($id); - $result = $object->create($user, $oldinvoice->id); - if ($result > 0) - { - $result=$oldinvoice->delete($user, 1); - if ($result < 0) - { - $error++; - setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors'); - $action = "create"; - } - } - else - { - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = "create"; - } + $result = $object->create($user, $oldinvoice->id); + if ($result > 0) + { + $result=$oldinvoice->delete($user, 1); + if ($result < 0) + { + $error++; + setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors'); + $action = "create"; + } + } + else + { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + $action = "create"; + } - if (! $error) - { - $db->commit(); + if (! $error) + { + $db->commit(); - header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id); - exit; - } - else - { - $db->rollback(); + header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id); + exit; + } + else + { + $db->rollback(); - $error++; - setEventMessages($object->error, $object->errors, 'errors'); - $action = "create"; - } - } - } + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + $action = "create"; + } + } + } - // Delete - if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer) - { - $object->delete($user); - header("Location: " . $_SERVER['PHP_SELF'] ); - exit; - } + // Delete + if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer) + { + $object->delete($user); + header("Location: " . $_SERVER['PHP_SELF'] ); + exit; + } - // Update field - // Set condition - if ($action == 'setconditions' && $user->rights->facture->creer) - { - $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + // Update field + // Set condition + if ($action == 'setconditions' && $user->rights->facture->creer) + { + $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - } - // Set mode - elseif ($action == 'setmode' && $user->rights->facture->creer) - { - $result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - } - // Set project - elseif ($action == 'classin' && $user->rights->facture->creer) - { - $object->setProject(GETPOST('projectid', 'int')); - } - // Set bank account - elseif ($action == 'setref' && $user->rights->facture->creer) - { - //var_dump(GETPOST('ref', 'alpha'));exit; - $result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); - if ($result > 0) - { - $object->titre = GETPOST('ref', 'alpha'); - $object->ref = $object->titre; - } - else dol_print_error($db, $object->error, $object->errors); - } - // Set bank account - elseif ($action == 'setbankaccount' && $user->rights->facture->creer) - { - $result=$object->setBankAccount(GETPOST('fk_account', 'int')); - } - // Set frequency and unit frequency - elseif ($action == 'setfrequency' && $user->rights->facture->creer) - { - $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha')); - } - // Set next date of execution - elseif ($action == 'setdate_when' && $user->rights->facture->creer) - { - $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear')); - if (!empty($date)) $object->setNextDate($date); - } - // Set max period - elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer) - { - $object->setMaxPeriod(GETPOST('nb_gen_max', 'int')); - } - // Set auto validate - elseif ($action == 'setauto_validate' && $user->rights->facture->creer) - { - $object->setAutoValidate(GETPOST('auto_validate', 'int')); - } + } + // Set mode + elseif ($action == 'setmode' && $user->rights->facture->creer) + { + $result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + } + // Set project + elseif ($action == 'classin' && $user->rights->facture->creer) + { + $object->setProject(GETPOST('projectid', 'int')); + } + // Set bank account + elseif ($action == 'setref' && $user->rights->facture->creer) + { + //var_dump(GETPOST('ref', 'alpha'));exit; + $result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); + if ($result > 0) + { + $object->titre = GETPOST('ref', 'alpha'); + $object->ref = $object->titre; + } + else dol_print_error($db, $object->error, $object->errors); + } + // Set bank account + elseif ($action == 'setbankaccount' && $user->rights->facture->creer) + { + $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + } + // Set frequency and unit frequency + elseif ($action == 'setfrequency' && $user->rights->facture->creer) + { + $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha')); + } + // Set next date of execution + elseif ($action == 'setdate_when' && $user->rights->facture->creer) + { + $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear')); + if (!empty($date)) $object->setNextDate($date); + } + // Set max period + elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer) + { + $object->setMaxPeriod(GETPOST('nb_gen_max', 'int')); + } + // Set auto validate + elseif ($action == 'setauto_validate' && $user->rights->facture->creer) + { + $object->setAutoValidate(GETPOST('auto_validate', 'int')); + } - // Delete line - if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) - { - $object->fetch($id); - $object->fetch_thirdparty(); + // Delete line + if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) + { + $object->fetch($id); + $object->fetch_thirdparty(); - $db->begin(); + $db->begin(); - $line=new FactureLigneRec($db); + $line=new FactureLigneRec($db); - // For triggers - $line->id = $lineid; + // For triggers + $line->id = $lineid; - if ($line->delete($user) > 0) - { - $result=$object->update_price(1); + if ($line->delete($user) > 0) + { + $result=$object->update_price(1); - if ($result > 0) - { - $db->commit(); - $object->fetch($object->id); // Reload lines - } - else - { - $db->rollback(); - setEventMessages($db->lasterror(), null, 'errors'); - } - } - else - { - $db->rollback(); - setEventMessages($line->error, $line->errors, 'errors'); - } - } - else if ($action == 'update_extras') - { - // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($result > 0) + { + $db->commit(); + $object->fetch($object->id); // Reload lines + } + else + { + $db->rollback(); + setEventMessages($db->lasterror(), null, 'errors'); + } + } + else + { + $db->rollback(); + setEventMessages($line->error, $line->errors, 'errors'); + } + } + else if ($action == 'update_extras') + { + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + if ($ret < 0) + $error ++; - if (! $error) { + if (! $error) { - $result = $object->insertExtraFields(); - if ($result < 0) { - $error ++; - } - } else if ($reshook < 0) - $error ++; + $result = $object->insertExtraFields(); + if ($result < 0) { + $error ++; + } + } else if ($reshook < 0) + $error ++; - if ($error) { - $action = 'edit_extras'; - setEventMessages($object->error, $object->errors, 'errors'); - } - } + if ($error) { + $action = 'edit_extras'; + setEventMessages($object->error, $object->errors, 'errors'); + } + } - // Add a new line - if ($action == 'addline' && $user->rights->facture->creer) - { - $langs->load('errors'); - $error = 0; + // Add a new line + if ($action == 'addline' && $user->rights->facture->creer) + { + $langs->load('errors'); + $error = 0; - // Set if we used free entry or predefined product - $predef=''; - $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); - $price_ht = GETPOST('price_ht'); - if (GETPOST('prod_entry_mode') == 'free') - { - $idprod=0; - $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - } - else - { - $idprod=GETPOST('idprod', 'int'); - $tva_tx = ''; - } + // Set if we used free entry or predefined product + $predef=''; + $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); + $price_ht = GETPOST('price_ht'); + if (GETPOST('prod_entry_mode') == 'free') + { + $idprod=0; + $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + } + else + { + $idprod=GETPOST('idprod', 'int'); + $tva_tx = ''; + } - $qty = GETPOST('qty' . $predef); - $remise_percent = GETPOST('remise_percent' . $predef); + $qty = GETPOST('qty' . $predef); + $remise_percent = GETPOST('remise_percent' . $predef); - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); - // Unset extrafield - if (is_array($extralabelsline)) - { - // Get extra fields - foreach ($extralabelsline as $key => $value) { - unset($_POST["options_" . $key . $predef]); - } - } + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + // Unset extrafield + if (is_array($extralabelsline)) + { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_" . $key . $predef]); + } + } - if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) { - setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors'); - $error ++; - } - if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); - $error ++; - } - if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); - $error ++; - } - if ($qty == '') { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); - $error ++; - } - if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); - $error ++; - } - if ($qty < 0) { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors'); - $error ++; - } + if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) { + setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); + $error ++; + } + if ($qty == '') { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); + $error ++; + } + if ($qty < 0) { + $langs->load("errors"); + setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors'); + $error ++; + } - if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) - { - $ret = $object->fetch($id); - if ($ret < 0) { - dol_print_error($db, $object->error); - exit(); - } - $ret = $object->fetch_thirdparty(); + if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) + { + $ret = $object->fetch($id); + if ($ret < 0) { + dol_print_error($db, $object->error); + exit(); + } + $ret = $object->fetch_thirdparty(); - // Clean parameters - $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); - $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); - $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT'); + // Clean parameters + $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); + $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); + $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT'); - // Define special_code for special lines - $special_code = 0; - // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices + // Define special_code for special lines + $special_code = 0; + // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices - // Ecrase $pu par celui du produit - // Ecrase $desc par celui du produit - // Ecrase $tva_tx par celui du produit - // Ecrase $base_price_type par celui du produit - // Replaces $fk_unit with the product's - if (! empty($idprod)) - { - $prod = new Product($db); - $prod->fetch($idprod); + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $tva_tx par celui du produit + // Ecrase $base_price_type par celui du produit + // Replaces $fk_unit with the product's + if (! empty($idprod)) + { + $prod = new Product($db); + $prod->fetch($idprod); - $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : ''); + $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : ''); - // Update if prices fields are defined - $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); - $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); - if (empty($tva_tx)) $tva_npr=0; + // Update if prices fields are defined + $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); + $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); + if (empty($tva_tx)) $tva_npr=0; - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_min = $prod->price_min; - $price_base_type = $prod->price_base_type; + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; - // We define price for product - if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level)) - { - $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; - $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; - $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; - $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; - if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility - { - if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; - if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; - if (empty($tva_tx)) $tva_npr=0; - } - } - elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { - require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; + // We define price for product + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level)) + { + $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; + $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; + $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; + $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility + { + if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; + if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + if (empty($tva_tx)) $tva_npr=0; + } + } + elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + { + require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - $prodcustprice = new Productcustomerprice($db); + $prodcustprice = new Productcustomerprice($db); - $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id); + $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id); - $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); - if ($result) - { - if (count($prodcustprice->lines) > 0) - { - $pu_ht = price($prodcustprice->lines[0]->price); - $pu_ttc = price($prodcustprice->lines[0]->price_ttc); - $price_base_type = $prodcustprice->lines[0]->price_base_type; - $tva_tx = $prodcustprice->lines[0]->tva_tx; - } - } - } + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); + if ($result) + { + if (count($prodcustprice->lines) > 0) + { + $pu_ht = price($prodcustprice->lines[0]->price); + $pu_ttc = price($prodcustprice->lines[0]->price_ttc); + $price_base_type = $prodcustprice->lines[0]->price_base_type; + $tva_tx = $prodcustprice->lines[0]->tva_tx; + } + } + } $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx)); $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); - // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ? - if (! empty($price_ht)) - { - $pu_ht = price2num($price_ht, 'MU'); - $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - elseif ($tmpvat != $tmpprodvat) - { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); - } - } + // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ? + if (! empty($price_ht)) + { + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + elseif ($tmpvat != $tmpprodvat) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); + } + } - $desc = ''; + $desc = ''; - // Define output language - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { - $outputlangs = $langs; - $newlang = ''; - if (empty($newlang) && GETPOST('lang_id','aZ09')) - $newlang = GETPOST('lang_id','aZ09'); - if (empty($newlang)) - $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } + // Define output language + if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) + { + $outputlangs = $langs; + $newlang = ''; + if (empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); + if (empty($newlang)) + $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } - $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; - } - else - { - $desc = $prod->description; - } + $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; + } + else + { + $desc = $prod->description; + } - $desc = dol_concatdesc($desc, $product_desc); + $desc = dol_concatdesc($desc, $product_desc); - // Add custom code and origin country into description - if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) - { - $tmptxt = '('; - if (! empty($prod->customcode)) - $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode; - if (! empty($prod->customcode) && ! empty($prod->country_code)) - $tmptxt .= ' - '; - if (! empty($prod->country_code)) - $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0); - $tmptxt .= ')'; - $desc = dol_concatdesc($desc, $tmptxt); + // Add custom code and origin country into description + if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) + { + $tmptxt = '('; + if (! empty($prod->customcode)) + $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode; + if (! empty($prod->customcode) && ! empty($prod->country_code)) + $tmptxt .= ' - '; + if (! empty($prod->country_code)) + $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0); + $tmptxt .= ')'; + $desc = dol_concatdesc($desc, $tmptxt); - } + } - $type = $prod->type; - $fk_unit = $prod->fk_unit; + $type = $prod->type; + $fk_unit = $prod->fk_unit; - } - else - { - $pu_ht = price2num($price_ht, 'MU'); - $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); - $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); - $tva_tx = str_replace('*', '', $tva_tx); - if (empty($tva_tx)) $tva_npr=0; - $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); - $desc = $product_desc; - $type = GETPOST('type'); - $fk_unit= GETPOST('units', 'alpha'); - } + } + else + { + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); + $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); + $tva_tx = str_replace('*', '', $tva_tx); + if (empty($tva_tx)) $tva_npr=0; + $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); + $desc = $product_desc; + $type = GETPOST('type'); + $fk_unit= GETPOST('units', 'alpha'); + } - // Margin - $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); - $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value + // Margin + $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); + $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value - // Local Taxes - $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr); - $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr); + // Local Taxes + $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr); + $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr); - $info_bits = 0; - if ($tva_npr) - $info_bits |= 0x01; + $info_bits = 0; + if ($tva_npr) + $info_bits |= 0x01; - if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) - { - $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); - setEventMessages($mesg, null, 'errors'); - } - else - { - // Insert line - $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit); + if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) + { + $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); + setEventMessages($mesg, null, 'errors'); + } + else + { + // Insert line + $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit); - if ($result > 0) - { - /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + if ($result > 0) + { + /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; @@ -665,114 +665,114 @@ if (empty($reshook)) $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); }*/ - $object->fetch($object->id); // Reload lines + $object->fetch($object->id); // Reload lines - unset($_POST['prod_entry_mode']); + unset($_POST['prod_entry_mode']); - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['remise_percent']); - unset($_POST['price_ht']); - unset($_POST['multicurrency_price_ht']); - unset($_POST['price_ttc']); - unset($_POST['tva_tx']); - unset($_POST['product_ref']); - unset($_POST['product_label']); - unset($_POST['product_desc']); - unset($_POST['fournprice']); - unset($_POST['buying_price']); - unset($_POST['np_marginRate']); - unset($_POST['np_markRate']); - unset($_POST['dp_desc']); - unset($_POST['idprod']); - unset($_POST['units']); + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['multicurrency_price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + unset($_POST['np_marginRate']); + unset($_POST['np_markRate']); + unset($_POST['dp_desc']); + unset($_POST['idprod']); + unset($_POST['units']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); - unset($_POST['situations']); - unset($_POST['progress']); - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } + unset($_POST['situations']); + unset($_POST['progress']); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } - $action = ''; - } - } - } + $action = ''; + } + } + } - elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel','alpha')) - { - if (! $object->fetch($id) > 0) dol_print_error($db); - $object->fetch_thirdparty(); + elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel','alpha')) + { + if (! $object->fetch($id) > 0) dol_print_error($db); + $object->fetch_thirdparty(); - // Clean parameters - $date_start = ''; - $date_end = ''; - //$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); - //$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); - $description = dol_htmlcleanlastbr(GETPOST('product_desc','none') ? GETPOST('product_desc','none') : GETPOST('desc','none')); - $pu_ht = GETPOST('price_ht'); - $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - $qty = GETPOST('qty'); + // Clean parameters + $date_start = ''; + $date_end = ''; + //$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); + //$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); + $description = dol_htmlcleanlastbr(GETPOST('product_desc','none') ? GETPOST('product_desc','none') : GETPOST('desc','none')); + $pu_ht = GETPOST('price_ht'); + $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + $qty = GETPOST('qty'); - // Define info_bits - $info_bits = 0; - if (preg_match('/\*/', $vat_rate)) - $info_bits |= 0x01; + // Define info_bits + $info_bits = 0; + if (preg_match('/\*/', $vat_rate)) + $info_bits |= 0x01; - // Define vat_rate - $vat_rate = str_replace('*', '', $vat_rate); - $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty); - $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty); + // Define vat_rate + $vat_rate = str_replace('*', '', $vat_rate); + $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty); + $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty); - // Add buying price - $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); - $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value + // Add buying price + $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); + $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline); - $objectline = new FactureLigneRec($db); - if ($objectline->fetch(GETPOST('lineid'))) - { - $objectline->array_options=$array_options; - $result=$objectline->insertExtraFields(); - if ($result < 0) - { - setEventMessages($langs->trans('Error').$result, null, 'errors'); - } - } + $objectline = new FactureLigneRec($db); + if ($objectline->fetch(GETPOST('lineid'))) + { + $objectline->array_options=$array_options; + $result=$objectline->insertExtraFields(); + if ($result < 0) + { + setEventMessages($langs->trans('Error').$result, null, 'errors'); + } + } - // Unset extrafield - if (is_array($extralabelsline)) - { - // Get extra fields - foreach ($extralabelsline as $key => $value) - { - unset($_POST["options_" . $key]); - } - } + // Unset extrafield + if (is_array($extralabelsline)) + { + // Get extra fields + foreach ($extralabelsline as $key => $value) + { + unset($_POST["options_" . $key]); + } + } - // Define special_code for special lines - $special_code=GETPOST('special_code'); - if (! GETPOST('qty')) $special_code=3; + // Define special_code for special lines + $special_code=GETPOST('special_code'); + if (! GETPOST('qty')) $special_code=3; - /*$line = new FactureLigne($db); + /*$line = new FactureLigne($db); $line->fetch(GETPOST('lineid')); $percent = $line->get_prev_progress($object->id); @@ -784,69 +784,69 @@ if (empty($reshook)) $result = -1; }*/ - // Check minimum price - $productid = GETPOST('productid', 'int'); - if (! empty($productid)) - { - $product = new Product($db); - $product->fetch($productid); + // Check minimum price + $productid = GETPOST('productid', 'int'); + if (! empty($productid)) + { + $product = new Product($db); + $product->fetch($productid); - $type = $product->type; + $type = $product->type; - $price_min = $product->price_min; - if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level)) - $price_min = $product->multiprices_min [$object->thirdparty->price_level]; + $price_min = $product->price_min; + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level)) + $price_min = $product->multiprices_min [$object->thirdparty->price_level]; - $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); + $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); - // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { - setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); - $error ++; - } - } else { - $type = GETPOST('type'); - $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); + // Check price is not lower than minimum (check is done only for standard or replacement invoices) + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { + setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); + $error ++; + } + } else { + $type = GETPOST('type'); + $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); - // Check parameters - if (GETPOST('type') < 0) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); - $error ++; - } - } - if ($qty < 0) { - $langs->load("errors"); - setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors'); - $error ++; - } + // Check parameters + if (GETPOST('type') < 0) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); + $error ++; + } + } + if ($qty < 0) { + $langs->load("errors"); + setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors'); + $error ++; + } - // Update line - if (! $error) - { - $result = $object->updateline( - GETPOST('lineid'), - $description, - $pu_ht, - $qty, - $vat_rate, - $localtax1_rate, - $localtax1_rate, - GETPOST('productid'), - GETPOST('remise_percent'), - 'HT', - $info_bits, - 0, - 0, - $type, - 0, - $special_code, - $label, - GETPOST('units') - ); + // Update line + if (! $error) + { + $result = $object->updateline( + GETPOST('lineid'), + $description, + $pu_ht, + $qty, + $vat_rate, + $localtax1_rate, + $localtax1_rate, + GETPOST('productid'), + GETPOST('remise_percent'), + 'HT', + $info_bits, + 0, + 0, + $type, + 0, + $special_code, + $label, + GETPOST('units') + ); - if ($result >= 0) - { - /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + if ($result >= 0) + { + /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language $outputlangs = $langs; $newlang = ''; @@ -863,50 +863,50 @@ if (empty($reshook)) $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); }*/ - $object->fetch($object->id); // Reload lines + $object->fetch($object->id); // Reload lines - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['productid']); - unset($_POST['remise_percent']); - unset($_POST['price_ht']); - unset($_POST['multicurrency_price_ht']); - unset($_POST['price_ttc']); - unset($_POST['tva_tx']); - unset($_POST['product_ref']); - unset($_POST['product_label']); - unset($_POST['product_desc']); - unset($_POST['fournprice']); - unset($_POST['buying_price']); - unset($_POST['np_marginRate']); - unset($_POST['np_markRate']); + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['productid']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['multicurrency_price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + unset($_POST['np_marginRate']); + unset($_POST['np_markRate']); - unset($_POST['dp_desc']); - unset($_POST['idprod']); - unset($_POST['units']); + unset($_POST['dp_desc']); + unset($_POST['idprod']); + unset($_POST['units']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); - unset($_POST['situations']); - unset($_POST['progress']); - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } + unset($_POST['situations']); + unset($_POST['progress']); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } } @@ -987,7 +987,7 @@ if ($action == 'create') $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; foreach($substitutionarray as $key => $val) { - $htmltext.=$key.' = '.$langs->trans($val).'
'; + $htmltext.=$key.' = '.$langs->trans($val).'
'; } $htmltext.='
'; @@ -998,20 +998,20 @@ if ($action == 'create') print ''; print ''; $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); + print $doleditor->Create(1); // Private note if (empty($user->societe_id)) { - print ''; - print ''; - print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'); - print ''; - print ''; - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); - // print ' - print ''; + print ''; + print ''; + print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'); + print ''; + print ''; + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + // print ' + print ''; } // Author @@ -1083,7 +1083,7 @@ if ($action == 'create') print ""; - dol_fiche_end(); + dol_fiche_end(); $title = $langs->trans("ProductsAndServices"); @@ -1102,10 +1102,10 @@ if ($action == 'create') // Show object lines if (! empty($object->lines)) { - $disableedit=1; - $disablemove=1; - $disableremove=1; - $ret = $object->printObjectLines('', $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice + $disableedit=1; + $disablemove=1; + $disableremove=1; + $ret = $object->printObjectLines('', $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice } print "\n"; @@ -1125,9 +1125,9 @@ if ($action == 'create') print "\n"; print '
'; - print '     '; - print ''; - print '
'; + print '     '; + print ''; + print ''; print "\n"; } else @@ -1171,53 +1171,53 @@ else if ($action != 'editref') $morehtmlref.=$form->editfieldkey($object->ref, 'ref', $object->ref, $object, $user->rights->facture->creer, '', '', 0, 2); else $morehtmlref.= $form->editfieldval('', 'ref', $object->ref, $object, $user->rights->facture->creer, 'string'); - $morehtmlref.='
'; - // Ref customer - //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); - //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); - // Thirdparty - $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->facture->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.='
'; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.='
'; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } - $morehtmlref.='
'; + $morehtmlref.='
'; + // Ref customer + //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); + //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); + // Thirdparty + $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->facture->creer) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.='
'; - dol_banner_tab($object, 'ref', $linkback, 1, 'titre', 'none', $morehtmlref, '', 0, '', $morehtmlright); + dol_banner_tab($object, 'ref', $linkback, 1, 'titre', 'none', $morehtmlref, '', 0, '', $morehtmlright); - print '
'; - print '
'; - print '
'; + print '
'; + print '
'; + print '
'; - print ''; + print '
'; print '"; @@ -1309,7 +1309,7 @@ else $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; foreach($substitutionarray as $key => $val) { - $htmltext.=$key.' = '.$langs->trans($val).'
'; + $htmltext.=$key.' = '.$langs->trans($val).'
'; } $htmltext.='
'; @@ -1337,16 +1337,16 @@ else print $langs->trans('RIB'); print ''; + print ''; print '
'.$langs->trans("Author").''.$author->getFullName($langs)."
'; if (($action != 'editbankaccount') && $user->rights->facture->creer && ! empty($object->brouillon)) - print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; print ''; if ($action == 'editbankaccount') { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); } else { - $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); } print ""; print ''; @@ -1356,12 +1356,12 @@ else $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - print ''; + print ''; - print '
'; - print '
'; - print '
'; - print '
'; + print '
'; + print '
'; + print '
'; + print '
'; /* @@ -1397,13 +1397,13 @@ else } else { - if ($object->frequency > 0) - { + if ($object->frequency > 0) + { print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency); - } - else - { - print $langs->trans("NotARecurringInvoiceTemplate"); + } + else + { + print $langs->trans("NotARecurringInvoiceTemplate"); } } print ''; @@ -1412,16 +1412,16 @@ else print ''; if ($action == 'date_when' || $object->frequency > 0) { - print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day'); + print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day'); } else { - print $langs->trans("NextDateToExecution"); + print $langs->trans("NextDateToExecution"); } print ''; if ($action == 'date_when' || $object->frequency > 0) { - print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached'); + print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached'); } print ''; print ''; @@ -1430,20 +1430,20 @@ else print ''; if ($action == 'nb_gen_max' || $object->frequency > 0) { - print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer); + print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer); } else { - print $langs->trans("MaxPeriodNumber"); + print $langs->trans("MaxPeriodNumber"); } print ''; if ($action == 'nb_gen_max' || $object->frequency > 0) { - print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', $object, $user->rights->facture->creer); + print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', $object, $user->rights->facture->creer); } else { - print ''; + print ''; } print ''; print ''; @@ -1451,51 +1451,51 @@ else // Status of generated invoices print ''; if ($action == 'auto_validate' || $object->frequency > 0) - print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer); + print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer); else - print $langs->trans("StatusOfGeneratedInvoices"); + print $langs->trans("StatusOfGeneratedInvoices"); print ''; - $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated'); + $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated'); if ($action == 'auto_validate' || $object->frequency > 0) { - print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select); + print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select); } print ''; print ''; print ''; - // Frequencry/Recurring section - if ($object->frequency > 0) - { - print '
'; + // Frequencry/Recurring section + if ($object->frequency > 0) + { + print '
'; - if (empty($conf->cron->enabled)) - { - print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"))); - } + if (empty($conf->cron->enabled)) + { + print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name"))); + } - print '
'; - print ''; + print '
'; + print '
'; - // Nb of generation already done - print ''; - print ''; - print ''; + // Nb of generation already done + print ''; + print ''; + print ''; - // Date last - print ''; - print ''; + // Date last + print ''; + print ''; - print '
'.$langs->trans("NbOfGenerationDone").''; - print $object->nb_gen_done?$object->nb_gen_done:'0'; - print '
'.$langs->trans("NbOfGenerationDone").''; + print $object->nb_gen_done?$object->nb_gen_done:'0'; + print '
'; - print $langs->trans("DateLastGeneration"); - print ''; - print dol_print_date($object->date_last_gen, 'dayhour'); - print '
'; + print $langs->trans("DateLastGeneration"); + print ''; + print dol_print_date($object->date_last_gen, 'dayhour'); + print '
'; + print ''; - print '
'; + print '
'; } print '
'; @@ -1514,7 +1514,7 @@ else '; if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { - include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; + include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } print '
'; @@ -1522,22 +1522,22 @@ else // Show object lines if (! empty($object->lines)) { - //$disableedit=1; - //$disablemove=1; - $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice + //$disableedit=1; + //$disablemove=1; + $ret = $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice } // Form to add new line if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') { - if ($action != 'editline') - { - // Add free products/services - $object->formAddObjectLine(0, $mysoc, $object->thirdparty); // No date selector for template invoice + if ($action != 'editline') + { + // Add free products/services + $object->formAddObjectLine(0, $mysoc, $object->thirdparty); // No date selector for template invoice - $parameters = array(); - $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - } + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } } print "\n"; @@ -1570,13 +1570,13 @@ else else { print ''; - } - } + } + } } else { print ''; - } + } //} //if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer) @@ -1594,12 +1594,12 @@ else // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice')); + $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - print '
'; + print '
'; } } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 8c8a3c2fc11..2122c958e34 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -109,16 +109,16 @@ if (empty($reshook)) if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { - $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); + $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); - if ($result > 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else { - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + setEventMessages($object->error, $object->errors, 'errors'); + } } else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer) @@ -130,47 +130,47 @@ if (empty($reshook)) } if (! $error) { - $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment'))); - if ($result > 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } + $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment'))); + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } } } // Si ajout champ produit predefini if (GETPOST('mode')=='predefined') { - $date_start=''; - $date_end=''; - if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) - { - $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); - } - if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) - { - $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); - } + $date_start=''; + $date_end=''; + if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) + { + $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); + } + if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) + { + $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); + } } // Si ajout champ produit libre if (GETPOST('mode')=='libre') { - $date_start_sl=''; - $date_end_sl=''; - if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear')) - { - $date_start_sl=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear')); - } - if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear')) - { - $date_end_sl=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear')); - } + $date_start_sl=''; + $date_end_sl=''; + if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear')) + { + $date_start_sl=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear')); + } + if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear')) + { + $date_end_sl=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear')); + } } // Param dates @@ -181,23 +181,23 @@ if (empty($reshook)) $date_end_real_update=''; if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear')) { - $date_start_update=dol_mktime(GETPOST('date_start_updatehour'), GETPOST('date_start_updatemin'), 0, GETPOST('date_start_updatemonth'), GETPOST('date_start_updateday'), GETPOST('date_start_updateyear')); + $date_start_update=dol_mktime(GETPOST('date_start_updatehour'), GETPOST('date_start_updatemin'), 0, GETPOST('date_start_updatemonth'), GETPOST('date_start_updateday'), GETPOST('date_start_updateyear')); } if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear')) { - $date_end_update=dol_mktime(GETPOST('date_end_updatehour'), GETPOST('date_end_updatemin'), 0, GETPOST('date_end_updatemonth'), GETPOST('date_end_updateday'), GETPOST('date_end_updateyear')); + $date_end_update=dol_mktime(GETPOST('date_end_updatehour'), GETPOST('date_end_updatemin'), 0, GETPOST('date_end_updatemonth'), GETPOST('date_end_updateday'), GETPOST('date_end_updateyear')); } if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear')) { - $date_start_real_update=dol_mktime(GETPOST('date_start_real_updatehour'), GETPOST('date_start_real_updatemin'), 0, GETPOST('date_start_real_updatemonth'), GETPOST('date_start_real_updateday'), GETPOST('date_start_real_updateyear')); + $date_start_real_update=dol_mktime(GETPOST('date_start_real_updatehour'), GETPOST('date_start_real_updatemin'), 0, GETPOST('date_start_real_updatemonth'), GETPOST('date_start_real_updateday'), GETPOST('date_start_real_updateyear')); } if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear')) { - $date_end_real_update=dol_mktime(GETPOST('date_end_real_updatehour'), GETPOST('date_end_real_updatemin'), 0, GETPOST('date_end_real_updatemonth'), GETPOST('date_end_real_updateday'), GETPOST('date_end_real_updateyear')); + $date_end_real_update=dol_mktime(GETPOST('date_end_real_updatehour'), GETPOST('date_end_real_updatemin'), 0, GETPOST('date_end_real_updatemonth'), GETPOST('date_end_real_updateday'), GETPOST('date_end_real_updateyear')); } if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear')) { - $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); } // Add contract @@ -228,74 +228,74 @@ if (empty($reshook)) if (! $error) { $object->socid = $socid; - $object->date_contrat = $datecontrat; + $object->date_contrat = $datecontrat; - $object->commercial_suivi_id = GETPOST('commercial_suivi_id','int'); - $object->commercial_signature_id = GETPOST('commercial_signature_id','int'); + $object->commercial_suivi_id = GETPOST('commercial_suivi_id','int'); + $object->commercial_signature_id = GETPOST('commercial_signature_id','int'); - $object->note_private = GETPOST('note_private','alpha'); - $object->note_public = GETPOST('note_public','alpha'); - $object->fk_project = GETPOST('projectid','int'); - $object->remise_percent = GETPOST('remise_percent','alpha'); - $object->ref = GETPOST('ref','alpha'); - $object->ref_customer = GETPOST('ref_customer','alpha'); - $object->ref_supplier = GETPOST('ref_supplier','alpha'); + $object->note_private = GETPOST('note_private','alpha'); + $object->note_public = GETPOST('note_public','alpha'); + $object->fk_project = GETPOST('projectid','int'); + $object->remise_percent = GETPOST('remise_percent','alpha'); + $object->ref = GETPOST('ref','alpha'); + $object->ref_customer = GETPOST('ref_customer','alpha'); + $object->ref_supplier = GETPOST('ref_supplier','alpha'); - // If creation from another object of another module (Example: origin=propal, originid=1) - if (! empty($origin) && ! empty($originid)) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = $origin; - if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - } + // If creation from another object of another module (Example: origin=propal, originid=1) + if (! empty($origin) && ! empty($originid)) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $origin; + if (preg_match('/^([^_]+)_([^_]+)/i',$origin,$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } - // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + // For compatibility + if ($element == 'order') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - $object->origin = $origin; - $object->origin_id = $originid; + $object->origin = $origin; + $object->origin_id = $originid; - // Possibility to add external linked objects with hooks - $object->linked_objects[$object->origin] = $object->origin_id; - if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) - { - $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); - } + // Possibility to add external linked objects with hooks + $object->linked_objects[$object->origin] = $object->origin_id; + if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) + { + $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); + } - $id = $object->create($user); - if ($id < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + $id = $object->create($user); + if ($id < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } - if ($id > 0) - { - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + if ($id > 0) + { + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - $srcobject = new $classname($db); + $classname = ucfirst($subelement); + $srcobject = new $classname($db); - dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); - $result=$srcobject->fetch($object->origin_id); - if ($result > 0) - { - $srcobject->fetch_thirdparty(); + dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); + $result=$srcobject->fetch($object->origin_id); + if ($result > 0) + { + $srcobject->fetch_thirdparty(); $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject,'fetch_lines')) - { - $srcobject->fetch_lines(); - $lines = $srcobject->lines; - } + if (empty($lines) && method_exists($srcobject,'fetch_lines')) + { + $srcobject->fetch_lines(); + $lines = $srcobject->lines; + } - $fk_parent_line=0; - $num=count($lines); + $fk_parent_line=0; + $num=count($lines); - for ($i=0;$i<$num;$i++) - { - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + for ($i=0;$i<$num;$i++) + { + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); if ($product_type == 1 || (! empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0,1)))) { // TODO Exclude also deee // service prédéfini @@ -330,8 +330,8 @@ if (empty($reshook)) $desc = ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?dol_htmlentitiesbr($lines[$i]->desc):''; } else { - $desc = dol_htmlentitiesbr($lines[$i]->desc); - } + $desc = dol_htmlentitiesbr($lines[$i]->desc); + } $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx . ' (' . $lines[$i]->vat_src_code . ')' : $lines[$i]->tva_tx; @@ -339,72 +339,72 @@ if (empty($reshook)) $localtax1_tx = get_localtax($txtva, 1, $object->thirdparty); $localtax2_tx = get_localtax($txtva, 2, $object->thirdparty); - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $txtva, - $localtax1_tx, - $localtax2_tx, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $lines[$i]->date_start, - $lines[$i]->date_end, - 'HT', - 0, - $lines[$i]->info_bits, - $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht, - array(), - $lines[$i]->fk_unit - ); + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $txtva, + $localtax1_tx, + $localtax2_tx, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $lines[$i]->date_start, + $lines[$i]->date_end, + 'HT', + 0, + $lines[$i]->info_bits, + $lines[$i]->fk_fournprice, + $lines[$i]->pa_ht, + array(), + $lines[$i]->fk_unit + ); - if ($result < 0) - { - $error++; - break; - } + if ($result < 0) + { + $error++; + break; + } } - } - } - else - { - setEventMessages($srcobject->error, $srcobject->errors, 'errors'); - $error++; - } + } + } + else + { + setEventMessages($srcobject->error, $srcobject->errors, 'errors'); + $error++; + } - // Hooks - $parameters = array('objFrom' => $srcobject); - $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been - // modified by hook - if ($reshook < 0) - $error++; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - else - { - $result = $object->create($user); - if ($result > 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else { - setEventMessages($object->error, $object->errors, 'errors'); - } - $action='create'; + // Hooks + $parameters = array('objFrom' => $srcobject); + $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been + // modified by hook + if ($reshook < 0) + $error++; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } } - } + else + { + $result = $object->create($user); + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + setEventMessages($object->error, $object->errors, 'errors'); + } + $action='create'; + } + } } else if ($action == 'classin' && $user->rights->contrat->creer) { - $object->setProject(GETPOST('projectid')); + $object->setProject(GETPOST('projectid')); } // Add a new line @@ -429,72 +429,72 @@ if (empty($reshook)) $qty = GETPOST('qty'.$predef); $remise_percent = GETPOST('remise_percent'.$predef); - if ($qty == '') - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); - $error++; - } - if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors'); - $error++; - } + if ($qty == '') + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); + $error++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors'); + $error++; + } - $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); - $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); - if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) - { - setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); - $error++; - } + $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); + $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); + if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) + { + setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); + $error++; + } - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); - // Unset extrafield - if (is_array($extralabelsline)) { - // Get extra fields - foreach ($extralabelsline as $key => $value) { - unset($_POST["options_" . $key]); - } - } + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_" . $key]); + } + } - if (! $error) - { + if (! $error) + { // Clean parameters $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); - // Ecrase $pu par celui du produit - // Ecrase $desc par celui du produit - // Ecrase $tva_tx par celui du produit - // Ecrase $base_price_type par celui du produit - if ($idprod > 0) - { - $prod = new Product($db); - $prod->fetch($idprod); + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $tva_tx par celui du produit + // Ecrase $base_price_type par celui du produit + if ($idprod > 0) + { + $prod = new Product($db); + $prod->fetch($idprod); - // Update if prices fields are defined - $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id); - $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id); - if (empty($tva_tx)) $tva_npr=0; + // Update if prices fields are defined + $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id); + $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id); + if (empty($tva_tx)) $tva_npr=0; - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_min = $prod->price_min; - $price_base_type = $prod->price_base_type; + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; - // On defini prix unitaire - if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) - { - $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; - $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; - $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; - $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; - } - elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + // On defini prix unitaire + if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) + { + $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; + $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; + $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; + $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; + } + elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; @@ -517,35 +517,35 @@ if (empty($reshook)) $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tmpvat != $tmpprodvat) - { - if ($price_base_type != 'HT') - { - $pu_ht = price2num($pu_ttc / (1 + ($tmpvat/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tmpvat/100)), 'MU'); - } - } + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tmpvat != $tmpprodvat) + { + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tmpvat/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tmpvat/100)), 'MU'); + } + } - $desc=$prod->description; - $desc=dol_concatdesc($desc,$product_desc); - $fk_unit = $prod->fk_unit; - } - else + $desc=$prod->description; + $desc=dol_concatdesc($desc,$product_desc); + $fk_unit = $prod->fk_unit; + } + else { - $pu_ht=GETPOST('price_ht'); - $price_base_type = 'HT'; - $tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0 - $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0; - $desc=$product_desc; + $pu_ht=GETPOST('price_ht'); + $price_base_type = 'HT'; + $tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0 + $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0; + $desc=$product_desc; $fk_unit= GETPOST('units', 'alpha'); - } + } - $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty,$mysoc,$tva_npr); - $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty,$mysoc,$tva_npr); + $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty,$mysoc,$tva_npr); + $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty,$mysoc,$tva_npr); // ajout prix achat $fk_fournprice = $_POST['fournprice']; @@ -554,41 +554,41 @@ if (empty($reshook)) else $pa_ht = null; - $info_bits=0; - if ($tva_npr) $info_bits |= 0x01; + $info_bits=0; + if ($tva_npr) $info_bits |= 0x01; - if($price_min && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min))) - { - $object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); - $result = -1 ; - } - else + if($price_min && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min))) { - // Insert line - $result = $object->addline( - $desc, - $pu_ht, - $qty, - $tva_tx, - $localtax1_tx, - $localtax2_tx, - $idprod, - $remise_percent, - $date_start, - $date_end, - $price_base_type, - $pu_ttc, - $info_bits, - $fk_fournprice, - $pa_ht, - $array_options, - $fk_unit - ); - } + $object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); + $result = -1 ; + } + else + { + // Insert line + $result = $object->addline( + $desc, + $pu_ht, + $qty, + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $idprod, + $remise_percent, + $date_start, + $date_end, + $price_base_type, + $pu_ttc, + $info_bits, + $fk_fournprice, + $pa_ht, + $array_options, + $fk_unit + ); + } - if ($result > 0) - { - // Define output language + if ($result > 0) + { + // Define output language if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && ! empty($conf->global->CONTRACT_ADDON_PDF)) // No generation if default type not defined { $outputlangs = $langs; @@ -624,159 +624,159 @@ if (empty($reshook)) unset($_POST['dp_desc']); unset($_POST['idprod']); - unset($_POST['date_starthour']); - unset($_POST['date_startmin']); - unset($_POST['date_startsec']); - unset($_POST['date_startday']); - unset($_POST['date_startmonth']); - unset($_POST['date_startyear']); - unset($_POST['date_endhour']); - unset($_POST['date_endmin']); - unset($_POST['date_endsec']); - unset($_POST['date_endday']); - unset($_POST['date_endmonth']); - unset($_POST['date_endyear']); - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } } else if ($action == 'updateline' && $user->rights->contrat->creer && ! GETPOST('cancel','alpha')) { - if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) - { - setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); - $action = 'editline'; - $_GET['rowid'] = GETPOST('elrowid'); - $error++; - } + if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) + { + setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors'); + $action = 'editline'; + $_GET['rowid'] = GETPOST('elrowid'); + $error++; + } - if (!$error) { - $objectline = new ContratLigne($db); - if ($objectline->fetch(GETPOST('elrowid'))) - { - $db->begin(); + if (!$error) { + $objectline = new ContratLigne($db); + if ($objectline->fetch(GETPOST('elrowid'))) + { + $db->begin(); - if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture; - if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture; + if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture; + if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture; - $vat_rate = GETPOST('eltva_tx'); - // Define info_bits - $info_bits = 0; - if (preg_match('/\*/', $vat_rate)) - $info_bits |= 0x01; + $vat_rate = GETPOST('eltva_tx'); + // Define info_bits + $info_bits = 0; + if (preg_match('/\*/', $vat_rate)) + $info_bits |= 0x01; - // Define vat_rate - $vat_rate = str_replace('*', '', $vat_rate); - $localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); - $localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); + // Define vat_rate + $vat_rate = str_replace('*', '', $vat_rate); + $localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); + $localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - $txtva = $vat_rate; + $txtva = $vat_rate; - // Clean vat code - $vat_src_code=''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { - $vat_src_code = $reg[1]; - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. - } + // Clean vat code + $vat_src_code=''; + if (preg_match('/\((.*)\)/', $txtva, $reg)) + { + $vat_src_code = $reg[1]; + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + } - // ajout prix d'achat - $fk_fournprice = $_POST['fournprice']; - if ( ! empty($_POST['buying_price']) ) - $pa_ht = $_POST['buying_price']; - else - $pa_ht = null; + // ajout prix d'achat + $fk_fournprice = $_POST['fournprice']; + if ( ! empty($_POST['buying_price']) ) + $pa_ht = $_POST['buying_price']; + else + $pa_ht = null; - $fk_unit = GETPOST('unit', 'alpha'); + $fk_unit = GETPOST('unit', 'alpha'); - $objectline->description=GETPOST('product_desc','none'); - $objectline->price_ht=GETPOST('elprice'); - $objectline->subprice=GETPOST('elprice'); - $objectline->qty=GETPOST('elqty'); - $objectline->remise_percent=GETPOST('elremise_percent'); - $objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0 - $objectline->vat_src_code=$vat_src_code; - $objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0; - $objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0; - $objectline->date_ouverture_prevue=$date_start_update; - $objectline->date_ouverture=$date_start_real_update; - $objectline->date_fin_validite=$date_end_update; - $objectline->date_cloture=$date_end_real_update; - $objectline->fk_user_cloture=$user->id; - $objectline->fk_fournprice=$fk_fournprice; - $objectline->pa_ht=$pa_ht; + $objectline->description=GETPOST('product_desc','none'); + $objectline->price_ht=GETPOST('elprice'); + $objectline->subprice=GETPOST('elprice'); + $objectline->qty=GETPOST('elqty'); + $objectline->remise_percent=GETPOST('elremise_percent'); + $objectline->tva_tx=($txtva?$txtva:0); // Field may be disabled, so we use vat rate 0 + $objectline->vat_src_code=$vat_src_code; + $objectline->localtax1_tx=is_numeric($localtax1_tx)?$localtax1_tx:0; + $objectline->localtax2_tx=is_numeric($localtax2_tx)?$localtax2_tx:0; + $objectline->date_ouverture_prevue=$date_start_update; + $objectline->date_ouverture=$date_start_real_update; + $objectline->date_fin_validite=$date_end_update; + $objectline->date_cloture=$date_end_real_update; + $objectline->fk_user_cloture=$user->id; + $objectline->fk_fournprice=$fk_fournprice; + $objectline->pa_ht=$pa_ht; - if ($fk_unit > 0) { - $objectline->fk_unit = GETPOST('unit'); - } else { - $objectline->fk_unit = null; - } + if ($fk_unit > 0) { + $objectline->fk_unit = GETPOST('unit'); + } else { + $objectline->fk_unit = null; + } - // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element); - $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); - $objectline->array_options=$array_options; + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + $objectline->array_options=$array_options; - // TODO verifier price_min si fk_product et multiprix + // TODO verifier price_min si fk_product et multiprix - $result=$objectline->update($user); - if ($result > 0) - { - $db->commit(); - } - else - { - setEventMessages($objectline->error, $objectline->errors, 'errors'); - $db->rollback(); - } - } - else - { - setEventMessages($objectline->error, $objectline->errors, 'errors'); - } - } + $result=$objectline->update($user); + if ($result > 0) + { + $db->commit(); + } + else + { + setEventMessages($objectline->error, $objectline->errors, 'errors'); + $db->rollback(); + } + } + else + { + setEventMessages($objectline->error, $objectline->errors, 'errors'); + } + } } else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) { - $result = $object->deleteline(GETPOST('lineid'),$user); + $result = $object->deleteline(GETPOST('lineid'),$user); - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } } else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { - $result = $object->validate($user); + $result = $object->validate($user); } else if ($action == 'reopen' && $user->rights->contrat->creer) { - $result = $object->reopen($user); + $result = $object->reopen($user); } // Close all lines else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->closeAll($user); + $object->closeAll($user); } // Close all lines else if ($action == 'confirm_activate' && $confirm == 'yes' && $user->rights->contrat->creer) { - $object->activateAll($user); + $object->activateAll($user); } else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) @@ -848,7 +848,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } - $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); + $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'editref_supplier'; @@ -857,10 +857,10 @@ if (empty($reshook)) exit; } } - else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); - exit; - } + else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit; + } } elseif ($action=='setref_customer') { @@ -873,8 +873,8 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } - $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); - if ($result < 0) { + $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $action = 'editref_customer'; } else { @@ -882,58 +882,58 @@ if (empty($reshook)) exit; } } - else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); - exit; - } + else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit; + } } elseif ($action=='setref') { - $cancelbutton = GETPOST('cancel','alpha'); + $cancelbutton = GETPOST('cancel','alpha'); - if (!$cancelbutton) { - $result = $object->fetch($id); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + if (!$cancelbutton) { + $result = $object->fetch($id); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } - $result = $object->setValueFrom('ref', GETPOST('ref','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'editref'; - } else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); - exit; - } - } - else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); - exit; - } + $result = $object->setValueFrom('ref', GETPOST('ref','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editref'; + } else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); + exit; + } + } + else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit; + } } elseif ($action=='setdate_contrat') { - $cancelbutton = GETPOST('cancel','alpha'); + $cancelbutton = GETPOST('cancel','alpha'); - if (!$cancelbutton) { - $result = $object->fetch($id); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + if (!$cancelbutton) { + $result = $object->fetch($id); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } $datacontrat=dol_mktime(GETPOST('date_contrathour'), GETPOST('date_contratmin'), 0, GETPOST('date_contratmonth'), GETPOST('date_contratday'), GETPOST('date_contratyear')); - $result = $object->setValueFrom('date_contrat', $datacontrat, '', null, 'date', '', $user, 'CONTRACT_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'editdate_contrat'; - } else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); - exit; - } - } - else { - header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); - exit; - } + $result = $object->setValueFrom('date_contrat', $datacontrat, '', null, 'date', '', $user, 'CONTRACT_MODIFY'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editdate_contrat'; + } else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); + exit; + } + } + else { + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit; + } } @@ -1051,74 +1051,74 @@ if ($action == 'create') { print load_fiche_titre($langs->trans('AddContract'),'','title_commercial.png'); - $soc = new Societe($db); - if ($socid>0) $soc->fetch($socid); + $soc = new Societe($db); + if ($socid>0) $soc->fetch($socid); - if (GETPOST('origin') && GETPOST('originid')) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); - if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - } + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); + if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + } - if ($element == 'project') - { - $projectid=GETPOST('originid'); - } - else - { - // For compatibility - if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } - if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'project') + { + $projectid=GETPOST('originid'); + } + else + { + // For compatibility + if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; } + if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); + dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - $objectsrc = new $classname($db); - $objectsrc->fetch(GETPOST('originid')); - if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); - $objectsrc->fetch_thirdparty(); + $classname = ucfirst($subelement); + $objectsrc = new $classname($db); + $objectsrc->fetch(GETPOST('originid')); + if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); + $objectsrc->fetch_thirdparty(); - $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); - $soc = $objectsrc->thirdparty; + $soc = $objectsrc->thirdparty; - $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''); - $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); + $note_private = (! empty($objectsrc->note_private) ? $objectsrc->note_private : ''); + $note_public = (! empty($objectsrc->note_public) ? $objectsrc->note_public : ''); - // Object source contacts list - $srccontactslist = $objectsrc->liste_contact(-1,'external',1); - } - } - else { + // Object source contacts list + $srccontactslist = $objectsrc->liste_contact(-1,'external',1); + } + } + else { $projectid = GETPOST('projectid','int'); $note_private = GETPOST("note_private"); $note_public = GETPOST("note_public"); } - $object->date_contrat = dol_now(); + $object->date_contrat = dol_now(); - print '
'; - print ''; + print ''; + print ''; - print ''; - print ''."\n"; - print ''; + print ''; + print ''."\n"; + print ''; - dol_fiche_head(); + dol_fiche_head(); - print ''; + print '
'; - // Ref + // Ref print ''; @@ -1130,7 +1130,7 @@ if ($action == 'create') print ''; print ''; - // Thirdparty + // Thirdparty print ''; print ''; if ($socid>0) @@ -1144,7 +1144,7 @@ if ($action == 'create') { print ''; } print ''."\n"; @@ -1163,75 +1163,75 @@ if ($action == 'create') print ''; } - // Commercial suivi - print ''; + // Commercial suivi + print ''; - // Commercial signature - print ''; + // Commercial signature + print ''; - print '"; + print '"; - // Project - if (! empty($conf->projet->enabled)) - { - $formproject=new FormProjets($db); + // Project + if (! empty($conf->projet->enabled)) + { + $formproject=new FormProjets($db); - print '"; - } - - print ''; - - if (empty($user->societe_id)) - { - print ''; - } - - // Other attributes - $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"', 'cols'=>3); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Other attributes - if (empty($reshook) && ! empty($extrafields->attribute_label)) { - print $object->showOptionals($extrafields, 'edit'); - } - - print "
'.$langs->trans('Ref').''; - if (! empty($modCodeContract->code_auto)) { - $tmpcode=$langs->trans("Draft"); - } else { - $tmpcode=''; - } + if (! empty($modCodeContract->code_auto)) { + $tmpcode=$langs->trans("Draft"); + } else { + $tmpcode=''; + } print $tmpcode; print '
'.$langs->trans('RefSupplier').'
'.$langs->trans('ThirdParty').''; print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300'); - print ' '.$langs->trans("AddThirdParty").''; + print ' '.$langs->trans("AddThirdParty").''; print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").''; - print $form->select_dolusers(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,''); - print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").''; + print $form->select_dolusers(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,''); + print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").''; - print $form->select_dolusers(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,''); - print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").''; + print $form->select_dolusers(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,''); + print '
'.$langs->trans("Date").''; - $form->select_date($datecontrat,'',0,0,'',"contrat"); - print "
'.$langs->trans("Date").''; + $form->select_date($datecontrat,'',0,0,'',"contrat"); + print "
'.$langs->trans("Project").''; - $formproject->select_projects(($soc->id>0?$soc->id:-1),$projectid,"projectid",0,0,1,1); - print "
'.$langs->trans("NotePublic").''; - $doleditor=new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
'.$langs->trans("NotePrivate").''; - $doleditor=new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print '
\n"; - - dol_fiche_end(); - - print '
'; - print ''; - print '     '; - print ''; - print '
'; - - if (is_object($objectsrc)) - { - print ''; - print ''; - - if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) - { - print '
'.$langs->trans("Note").': '.$langs->trans("OnlyLinesWithTypeServiceAreUsed"); - } + print ''.$langs->trans("Project").''; + $formproject->select_projects(($soc->id>0?$soc->id:-1),$projectid,"projectid",0,0,1,1); + print ""; } - print "
\n"; + print ''.$langs->trans("NotePublic").''; + $doleditor=new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print ''; + + if (empty($user->societe_id)) + { + print ''.$langs->trans("NotePrivate").''; + $doleditor=new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print ''; + } + + // Other attributes + $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"', 'cols'=>3); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Other attributes + if (empty($reshook) && ! empty($extrafields->attribute_label)) { + print $object->showOptionals($extrafields, 'edit'); + } + + print "\n"; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + if (is_object($objectsrc)) + { + print ''; + print ''; + + if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) + { + print '
'.$langs->trans("Note").': '.$langs->trans("OnlyLinesWithTypeServiceAreUsed"); + } + } + + print "\n"; } else /* *************************************************************************** */ @@ -1240,105 +1240,105 @@ else /* */ /* *************************************************************************** */ { - $now=dol_now(); + $now=dol_now(); - if ($object->id > 0) - { - $object->fetch_thirdparty(); + if ($object->id > 0) + { + $object->fetch_thirdparty(); - $result=$object->fetch_lines(); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed - if ($result < 0) dol_print_error($db,$object->error); + $result=$object->fetch_lines(); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed + if ($result < 0) dol_print_error($db,$object->error); - $nbofservices=count($object->lines); + $nbofservices=count($object->lines); - $author = new User($db); - $author->fetch($object->user_author_id); + $author = new User($db); + $author->fetch($object->user_author_id); - $commercial_signature = new User($db); - $commercial_signature->fetch($object->commercial_signature_id); + $commercial_signature = new User($db); + $commercial_signature->fetch($object->commercial_signature_id); - $commercial_suivi = new User($db); - $commercial_suivi->fetch($object->commercial_suivi_id); + $commercial_suivi = new User($db); + $commercial_suivi->fetch($object->commercial_suivi_id); - $head = contract_prepare_head($object); + $head = contract_prepare_head($object); - $hselected = 0; + $hselected = 0; - dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract'); + dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract'); - /* + /* * Confirmation de la suppression du contrat */ - if ($action == 'delete') - { - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1); + if ($action == 'delete') + { + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1); - } + } - /* + /* * Confirmation de la validation */ - if ($action == 'valid') - { - $ref = substr($object->ref, 1, 4); - if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) - { - $numref = $object->getNextNumRef($object->thirdparty); - } - else - { - $numref = $object->ref; - } + if ($action == 'valid') + { + $ref = substr($object->ref, 1, 4); + if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) + { + $numref = $object->getNextNumRef($object->thirdparty); + } + else + { + $numref = $object->ref; + } - $text=$langs->trans('ConfirmValidateContract',$numref); + $text=$langs->trans('ConfirmValidateContract',$numref); - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$text,"confirm_valid",'',0,1); + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$text,"confirm_valid",'',0,1); - } + } - /* + /* * Confirmation de la fermeture */ - if ($action == 'close') - { - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1); + if ($action == 'close') + { + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1); - } - if ($action == 'activate') - { - print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ActivateAllOnContract"),$langs->trans("ConfirmActivateAllOnContract"),"confirm_activate",'',0,1); + } + if ($action == 'activate') + { + print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ActivateAllOnContract"),$langs->trans("ConfirmActivateAllOnContract"),"confirm_activate",'',0,1); - } + } - /* + /* * Contrat */ - if (! empty($object->brouillon) && $user->rights->contrat->creer) - { - print '
'; - print ''; - print ''; - } + if (! empty($object->brouillon) && $user->rights->contrat->creer) + { + print ''; + print ''; + print ''; + } - // Clone confirmation - if ($action == 'clone') { - $formquestion = array(array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)'))); - print $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneContract'), $langs->trans('ConfirmCloneContract', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); - } + // Clone confirmation + if ($action == 'clone') { + $formquestion = array(array('type' => 'other','name' => 'socid','label' => $langs->trans("SelectThirdParty"),'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)'))); + print $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CloneContract'), $langs->trans('ConfirmCloneContract', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); + } // Contract card - $linkback = ''.$langs->trans("BackToList").''; + $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref=''; - if (! empty($modCodeContract->code_auto)) { - $morehtmlref.=$object->ref; - } else { - $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,3); - $morehtmlref.=$form->editfieldval("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,2); - } + $morehtmlref=''; + if (! empty($modCodeContract->code_auto)) { + $morehtmlref.=$object->ref; + } else { + $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,3); + $morehtmlref.=$form->editfieldval("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,2); + } $morehtmlref.='
'; // Ref customer @@ -1349,64 +1349,64 @@ else $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', 0, 1); $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->contrat->creer) - { - if ($action != 'classify') - $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=''; - $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref.=''; - $morehtmlref.=''; - } else { - $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1); - } - } else { - if (! empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref.=''; - $morehtmlref.=$proj->ref; - $morehtmlref.=''; - } else { - $morehtmlref.=''; - } - } - } - $morehtmlref.='
'; + $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref.='
'.$langs->trans('Project') . ' '; + if ($user->rights->contrat->creer) + { + if ($action != 'classify') + $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; + if ($action == 'classify') { + //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref.='
'; + $morehtmlref.=''; + $morehtmlref.=''; + $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref.=''; + $morehtmlref.='
'; + } else { + $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (! empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref.=''; + $morehtmlref.=$proj->ref; + $morehtmlref.=''; + } else { + $morehtmlref.=''; + } + } + } + $morehtmlref.='
'; - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref); - print '
'; - print '
'; + print '
'; + print '
'; - print ''; + print '
'; - // Ligne info remises tiers - print ''; + // Ligne info remises tiers + print ''; - // Date - print ''; + // Date + print ''; print ''; print ''; - // Other attributes - $cols = 3; - include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; + // Other attributes + $cols = 3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; - print "
'.$langs->trans('Discount').''; - if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$object->thirdparty->getAvailableDiscounts(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print '
'.$langs->trans('Discount').''; + if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$object->thirdparty->getAvailableDiscounts(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print '
'; print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,$user->rights->contrat->creer); print ''; @@ -1414,577 +1414,577 @@ else print '
"; + print ""; - print '
'; + print '
'; - if (! empty($object->brouillon) && $user->rights->contrat->creer) - { - print ''; - } + if (! empty($object->brouillon) && $user->rights->contrat->creer) + { + print ''; + } - echo '
'; + echo '
'; - if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) - { - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) + { + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } - if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } + if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } - $colorb='666666'; + $colorb='666666'; - $arrayothercontracts=$object->getListOfContracts('others'); + $arrayothercontracts=$object->getListOfContracts('others'); - /* + /* * Lines of contracts */ $productstatic=new Product($db); - $usemargins=0; + $usemargins=0; if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; - $var=false; + $var=false; // Title line for service - $cursorline=1; - while ($cursorline <= $nbofservices) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; + $cursorline=1; + while ($cursorline <= $nbofservices) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - // Area with common detail of line - print ''; + // Area with common detail of line + print '
'; - $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,"; - $sql.= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,"; - $sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,"; - $sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,"; - $sql.= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,"; - $sql.= " cd.fk_unit,"; - $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity"; - $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; - $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id; + $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,"; + $sql.= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,"; + $sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,"; + $sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,"; + $sql.= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,"; + $sql.= " cd.fk_unit,"; + $sql.= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity"; + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; + $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id; - $result = $db->query($sql); - if ($result) - { - $total = 0; + $result = $db->query($sql); + if ($result) + { + $total = 0; - print ''; - print ''; - print ''; - print ''; - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - print ''; - if ($conf->global->PRODUCT_USE_UNITS) print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + if (!empty($conf->multicurrency->enabled)) { + print ''; + } + print ''; + if ($conf->global->PRODUCT_USE_UNITS) print ''; + print ''; if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''; - print ''; - print "\n"; + print ''; + print "\n"; - $objp = $db->fetch_object($result); + $objp = $db->fetch_object($result); - // + // - if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) - { - print ''; - // Label - if ($objp->fk_product > 0) - { - print ''; + // Label + if ($objp->fk_product > 0) + { + print ''; - } - else + print ''; + } + else { - print '\n"; - } - // TVA - print ''; - // Price - print '\n"; - // Price multicurrency - if (!empty($conf->multicurrency->enabled)) { - print ''; - } - // Quantite - print ''; - // Unit - if($conf->global->PRODUCT_USE_UNITS) print ''; - // Remise - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } + print '\n"; + } + // TVA + print ''; + // Price + print '\n"; + // Price multicurrency + if (!empty($conf->multicurrency->enabled)) { + print ''; + } + // Quantite + print ''; + // Unit + if($conf->global->PRODUCT_USE_UNITS) print ''; + // Remise + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } // Margin if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''; - // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme) - print ''; + // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme) + print ''; - print "\n"; + print "\n"; - // Dates of service planed and real - if ($objp->subprice >= 0) - { - $colspan = 6; + // Dates of service planed and real + if ($objp->subprice >= 0) + { + $colspan = 6; - if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) { - $colspan = 8; - } elseif ($conf->margin->enabled || $conf->global->PRODUCT_USE_UNITS) { - $colspan = 7; - } + if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) { + $colspan = 8; + } elseif ($conf->margin->enabled || $conf->global->PRODUCT_USE_UNITS) { + $colspan = 7; + } - print ''; - print ''; + print ''; - print ''; - } + print ''; + print ''; + } - // Display lines extrafields - if (is_array($extralabelslines) && count($extralabelslines)>0) { - print ''; - $line = new ContratLigne($db); - $line->fetch_optionals($objp->rowid,$extralabelslines); - print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bcnd[$var], 'colspan'=>$colspan)); - print ''; - } - } - // Ligne en mode update - else - { - // Ligne carac - print ""; - print ''; + $line = new ContratLigne($db); + $line->fetch_optionals($objp->rowid,$extralabelslines); + print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bcnd[$var], 'colspan'=>$colspan)); + print ''; + } + } + // Ligne en mode update + else + { + // Ligne carac + print ""; + print ''; - print ''; - print ''; - print ''; - if ($conf->global->PRODUCT_USE_UNITS) - { - print ''; - } - print ''; + print ''; + print ''; + print ''; + print ''; + if ($conf->global->PRODUCT_USE_UNITS) + { + print ''; + } + print ''; if (! empty($usemargins)) { - print ''; } - print ''; + print ''; - $colspan=6; - if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) $colspan++; - if($conf->global->PRODUCT_USE_UNITS) $colspan++; + $colspan=6; + if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) $colspan++; + if($conf->global->PRODUCT_USE_UNITS) $colspan++; - // Ligne dates prevues - print ""; - print ''; + // Ligne dates prevues + print ""; + print ''; - if (is_array($extralabelslines) && count($extralabelslines)>0) { - print ''; - $line = new ContratLigne($db); - $line->fetch_optionals($objp->rowid,$extralabelslines); - print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$colspan)); - print ''; - } + if (is_array($extralabelslines) && count($extralabelslines)>0) { + print ''; + $line = new ContratLigne($db); + $line->fetch_optionals($objp->rowid,$extralabelslines); + print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$colspan)); + print ''; + } - print ''; - } + print ''; + } - $db->free($result); - } - else + $db->free($result); + } + else { - dol_print_error($db); - } + dol_print_error($db); + } - if ($object->statut > 0) - { - print ''; - print ''; - print "\n"; - } + if ($object->statut > 0) + { + print ''; + print ''; + print "\n"; + } - print "
'.$langs->trans("ServiceNb",$cursorline).''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("PriceUHTCurrency").''.$langs->trans("Qty").''.$langs->trans("Unit").''.$langs->trans("ReductionShort").'
'.$langs->trans("ServiceNb",$cursorline).''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("PriceUHTCurrency").''.$langs->trans("Qty").''.$langs->trans("Unit").''.$langs->trans("ReductionShort").''.$langs->trans("BuyingPrice").' 
 
'; - $productstatic->id=$objp->fk_product; - $productstatic->type=$objp->ptype; - $productstatic->ref=$objp->pref; + if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) + { + print '
'; + $productstatic->id=$objp->fk_product; + $productstatic->type=$objp->ptype; + $productstatic->ref=$objp->pref; $productstatic->entity=$objp->pentity; $productstatic->label=$objp->plabel; $text = $productstatic->getNomUrl(1,'',20); - if ($objp->plabel) - { - $text .= ' - '; - //$productstatic->ref=$objp->label; - //$text .= $productstatic->getNomUrl(0,'',16); - $text .= $objp->plabel; - } - $description = $objp->description; + if ($objp->plabel) + { + $text .= ' - '; + //$productstatic->ref=$objp->label; + //$text .= $productstatic->getNomUrl(0,'',16); + $text .= $objp->plabel; + } + $description = $objp->description; - // Add description in form + // Add description in form if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) { $text .= (! empty($objp->description) && $objp->description!=$objp->plabel)?'
'.dol_htmlentitiesbr($objp->description):''; $description = ''; // Already added into main visible desc } - echo $form->textwithtooltip($text,$description,3,'','',$cursorline,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); + echo $form->textwithtooltip($text,$description,3,'','',$cursorline,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):'')); - print '
'.img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description)."'; - print vatrate($objp->tva_tx.($objp->vat_src_code?(' ('.$objp->vat_src_code.')'):''), '%', $objp->info_bits); - print ''.($objp->subprice != '' ? price($objp->subprice) : '')."'.price($objp->multicurrency_subprice).''.$objp->qty.''.$langs->trans($object->lines[$cursorline-1]->getLabelOfUnit()).''.$objp->remise_percent."% '.img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description)."'; + print vatrate($objp->tva_tx.($objp->vat_src_code?(' ('.$objp->vat_src_code.')'):''), '%', $objp->info_bits); + print ''.($objp->subprice != '' ? price($objp->subprice) : '')."'.price($objp->multicurrency_subprice).''.$objp->qty.''.$langs->trans($object->lines[$cursorline-1]->getLabelOfUnit()).''.$objp->remise_percent."% '.price($objp->pa_ht).''; - if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) - { - print ''; - print img_picto($langs->trans("MoveToAnotherContract"),'uparrow'); - print ''; - } - if ($user->rights->contrat->creer && ($object->statut >= 0)) - { - print ''; - print img_edit(); - print ''; - } - if ( $user->rights->contrat->creer && ($object->statut >= 0)) - { - print ''; - print img_delete(); - print ''; - } - print ''; + if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) + { + print ''; + print img_picto($langs->trans("MoveToAnotherContract"),'uparrow'); + print ''; + } + if ($user->rights->contrat->creer && ($object->statut >= 0)) + { + print ''; + print img_edit(); + print ''; + } + if ( $user->rights->contrat->creer && ($object->statut >= 0)) + { + print ''; + print img_delete(); + print ''; + } + print '
'; + print '
'; - // Date planned - print $langs->trans("DateStartPlanned").': '; - if ($objp->date_debut) - { - print dol_print_date($db->jdate($objp->date_debut), 'day'); - // Warning si date prevu passee et pas en service - if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { - $warning_delay=$conf->contrat->services->inactifs->warning_delay / 3600 / 24; - $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); - print " ".img_warning($textlate); - } - } - else print $langs->trans("Unknown"); - print '  -  '; - print $langs->trans("DateEndPlanned").': '; - if ($objp->date_fin) - { - print dol_print_date($db->jdate($objp->date_fin), 'day'); - if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { - $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24; - $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); - print " ".img_warning($textlate); - } - } - else print $langs->trans("Unknown"); + // Date planned + print $langs->trans("DateStartPlanned").': '; + if ($objp->date_debut) + { + print dol_print_date($db->jdate($objp->date_debut), 'day'); + // Warning si date prevu passee et pas en service + if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { + $warning_delay=$conf->contrat->services->inactifs->warning_delay / 3600 / 24; + $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); + print " ".img_warning($textlate); + } + } + else print $langs->trans("Unknown"); + print '  -  '; + print $langs->trans("DateEndPlanned").': '; + if ($objp->date_fin) + { + print dol_print_date($db->jdate($objp->date_fin), 'day'); + if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { + $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24; + $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); + print " ".img_warning($textlate); + } + } + else print $langs->trans("Unknown"); - print '
'; - if ($objp->fk_product) - { - $productstatic->id=$objp->fk_product; - $productstatic->type=$objp->ptype; - $productstatic->ref=$objp->pref; + // Display lines extrafields + if (is_array($extralabelslines) && count($extralabelslines)>0) { + print '
'; + if ($objp->fk_product) + { + $productstatic->id=$objp->fk_product; + $productstatic->type=$objp->ptype; + $productstatic->ref=$objp->pref; $productstatic->entity=$objp->pentity; - print $productstatic->getNomUrl(1,'',20); - print $objp->label?' - '.dol_trunc($objp->label,16):''; - print '
'; - } - else - { - print $objp->label?$objp->label.'
':''; - } + print $productstatic->getNomUrl(1,'',20); + print $objp->label?' - '.dol_trunc($objp->label,16):''; + print '
'; + } + else + { + print $objp->label?$objp->label.'
':''; + } - // editeur wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); - $doleditor=new DolEditor('product_desc',$objp->description,'',92,'dolibarr_details','',false,true,$enable,$nbrows,'90%'); - $doleditor->Create(); + // editeur wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); + $doleditor=new DolEditor('product_desc',$objp->description,'',92,'dolibarr_details','',false,true,$enable,$nbrows,'90%'); + $doleditor->Create(); - print '
'; - print $form->load_tva("eltva_tx", $objp->tva_tx.($objp->vat_src_code?(' ('.$objp->vat_src_code.')'):''), $mysoc, $object->thirdparty, $objp->fk_product, $objp->info_bits, $objp->product_type, 0, 1); - print ''; - print $form->selectUnits($objp->fk_unit, "unit"); - print '%'; + print $form->load_tva("eltva_tx", $objp->tva_tx.($objp->vat_src_code?(' ('.$objp->vat_src_code.')'):''), $mysoc, $object->thirdparty, $objp->fk_product, $objp->info_bits, $objp->product_type, 0, 1); + print ''; + print $form->selectUnits($objp->fk_unit, "unit"); + print '%'; - if ($objp->fk_product) print ''; + print ''; + if ($objp->fk_product) print ''; print ''; - print ''; - print '
'; - print '
'; + print ''; + print '
'; + print '
'; - print $langs->trans("DateStartPlanned").' '; - $form->select_date($db->jdate($objp->date_debut),"date_start_update",$usehm,$usehm,($db->jdate($objp->date_debut)>0?0:1),"update"); - print '   '.$langs->trans("DateEndPlanned").' '; - $form->select_date($db->jdate($objp->date_fin),"date_end_update",$usehm,$usehm,($db->jdate($objp->date_fin)>0?0:1),"update"); - print '
'; + print $langs->trans("DateStartPlanned").' '; + $form->select_date($db->jdate($objp->date_debut),"date_start_update",$usehm,$usehm,($db->jdate($objp->date_debut)>0?0:1),"update"); + print '   '.$langs->trans("DateEndPlanned").' '; + $form->select_date($db->jdate($objp->date_fin),"date_end_update",$usehm,$usehm,($db->jdate($objp->date_fin)>0?0:1),"update"); + print '


"; + print ""; - print "
\n"; + print "\n"; - /* + /* * Confirmation to delete service line of contract */ - if ($action == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid')) - { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1); - if ($ret == 'html') print '
'; - } + if ($action == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid')) + { + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1); + if ($ret == 'html') print '
'; + } - /* + /* * Confirmation to move service toward another contract */ - if ($action == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid')) - { - $arraycontractid=array(); - foreach($arrayothercontracts as $contractcursor) - { - $arraycontractid[$contractcursor->id]=$contractcursor->ref; - } - //var_dump($arraycontractid); - // Cree un tableau formulaire - $formquestion=array( + if ($action == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid')) + { + $arraycontractid=array(); + foreach($arrayothercontracts as $contractcursor) + { + $arraycontractid[$contractcursor->id]=$contractcursor->ref; + } + //var_dump($arraycontractid); + // Cree un tableau formulaire + $formquestion=array( 'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"), - array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid)); + array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid)); - $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion); - print '
'; - } + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion); + print '
'; + } - /* + /* * Confirmation de la validation activation */ - if ($action == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne')) - { - $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment','alpha'); - $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1); - print '
'; - } + if ($action == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne')) + { + $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + $comment = GETPOST('comment','alpha'); + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1); + print '
'; + } - /* + /* * Confirmation de la validation fermeture */ - if ($action == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne')) - { - $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment','alpha'); + if ($action == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne')) + { + $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + $comment = GETPOST('comment','alpha'); - if (empty($dateactend)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors'); - } - else - { - $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne','int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1); - } - print '
'; - } + if (empty($dateactend)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors'); + } + else + { + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne','int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1); + } + print '
'; + } - // Area with status and activation info of line - if ($object->statut > 0) - { - print ''; + // Area with status and activation info of line + if ($object->statut > 0) + { + print '
'; - print ''; - print ''; - print ''; + print ''; + print ''; - print "\n"; + } + } + print ''; + print "\n"; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; - print '
'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline-1]->getLibStatut(4).''; - if ($user->societe_id == 0) - { - if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') - { - $tmpaction='activateline'; - $tmpactionpicto='play'; - $tmpactiontext=$langs->trans("Activate"); - if ($objp->statut == 4) - { - $tmpaction='unactivateline'; - $tmpactionpicto='playstop'; - $tmpactiontext=$langs->trans("Unactivate"); - } + print '
'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline-1]->getLibStatut(4).''; + if ($user->societe_id == 0) + { + if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') + { + $tmpaction='activateline'; + $tmpactionpicto='play'; + $tmpactiontext=$langs->trans("Activate"); + if ($objp->statut == 4) + { + $tmpaction='unactivateline'; + $tmpactionpicto='playstop'; + $tmpactiontext=$langs->trans("Unactivate"); + } if (($tmpaction=='activateline' && $user->rights->contrat->activer) || ($tmpaction=='unactivateline' && $user->rights->contrat->desactiver)) { print ''; print img_picto($tmpactiontext, $tmpactionpicto); print ''; } - } - } - print '
'; - // Si pas encore active - if (! $objp->date_debut_reelle) { - print $langs->trans("DateStartReal").': '; - if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle, 'day'); - else print $langs->trans("ContractStatusNotRunning"); - } - // Si active et en cours - if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { - print $langs->trans("DateStartReal").': '; - print dol_print_date($objp->date_debut_reelle, 'day'); - } - // Si desactive - if ($objp->date_debut_reelle && $objp->date_fin_reelle) { - print $langs->trans("DateStartReal").': '; - print dol_print_date($objp->date_debut_reelle, 'day'); - print '  -  '; - print $langs->trans("DateEndReal").': '; - print dol_print_date($objp->date_fin_reelle, 'day'); - } - if (! empty($objp->comment)) print "
".$objp->comment; - print '
'; + // Si pas encore active + if (! $objp->date_debut_reelle) { + print $langs->trans("DateStartReal").': '; + if ($objp->date_debut_reelle) print dol_print_date($objp->date_debut_reelle, 'day'); + else print $langs->trans("ContractStatusNotRunning"); + } + // Si active et en cours + if ($objp->date_debut_reelle && ! $objp->date_fin_reelle) { + print $langs->trans("DateStartReal").': '; + print dol_print_date($objp->date_debut_reelle, 'day'); + } + // Si desactive + if ($objp->date_debut_reelle && $objp->date_fin_reelle) { + print $langs->trans("DateStartReal").': '; + print dol_print_date($objp->date_debut_reelle, 'day'); + print '  -  '; + print $langs->trans("DateEndReal").': '; + print dol_print_date($objp->date_fin_reelle, 'day'); + } + if (! empty($objp->comment)) print "
".$objp->comment; + print '
  
'; - } + print ''; + print ''; + } - // Form to activate line - if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline-1]->id == GETPOST('ligne')) - { - print '
'; - print ''; + // Form to activate line + if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline-1]->id == GETPOST('ligne')) + { + print ''; + print ''; - print ''; + print '
'; - // Definie date debut et fin par defaut - $dateactstart = $objp->date_debut; - if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - elseif (! $dateactstart) $dateactstart = time(); + // Definie date debut et fin par defaut + $dateactstart = $objp->date_debut; + if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + elseif (! $dateactstart) $dateactstart = time(); - $dateactend = $objp->date_fin; - if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - elseif (! $dateactend) - { - if ($objp->fk_product > 0) - { - $product=new Product($db); - $product->fetch($objp->fk_product); - $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); - } - } + $dateactend = $objp->date_fin; + if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + elseif (! $dateactend) + { + if ($objp->fk_product > 0) + { + $product=new Product($db); + $product->fetch($objp->fk_product); + $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); + } + } - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - print '
'.$langs->trans("DateServiceActivate").''; - print $form->select_date($dateactstart,'',$usehm,$usehm,'',"active",1,0,1); - print ''.$langs->trans("DateEndPlanned").''; - print $form->select_date($dateactend,"end",$usehm,$usehm,'',"active",1,0,1); - print ''; - print '
'.$langs->trans("DateServiceActivate").''; + print $form->select_date($dateactstart,'',$usehm,$usehm,'',"active",1,0,1); + print ''.$langs->trans("DateEndPlanned").''; + print $form->select_date($dateactend,"end",$usehm,$usehm,'',"active",1,0,1); + print ''; + print '
'.$langs->trans("Comment").''; - print '   '; - print ''; - print '
'.$langs->trans("Comment").''; + print '   '; + print ''; + print '
'; + print ''; - print '
'; - } + print ''; + } - if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline-1]->id == GETPOST('ligne')) - { - /** - * Disable a contract line - */ - print ''."\n"; - print '
'; + if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline-1]->id == GETPOST('ligne')) + { + /** + * Disable a contract line + */ + print ''."\n"; + print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print '
'; - // Definie date debut et fin par defaut - $dateactstart = $objp->date_debut_reelle; - if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - elseif (! $dateactstart) $dateactstart = time(); + // Definie date debut et fin par defaut + $dateactstart = $objp->date_debut_reelle; + if (GETPOST('remonth')) $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + elseif (! $dateactstart) $dateactstart = time(); - $dateactend = $objp->date_fin_reelle; - if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - elseif (! $dateactend) - { - if ($objp->fk_product > 0) - { - $product=new Product($db); - $product->fetch($objp->fk_product); - $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); - } - } - $now=dol_now(); - if ($dateactend > $now) $dateactend=$now; + $dateactend = $objp->date_fin_reelle; + if (GETPOST('endmonth')) $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + elseif (! $dateactend) + { + if ($objp->fk_product > 0) + { + $product=new Product($db); + $product->fetch($objp->fk_product); + $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit); + } + } + $now=dol_now(); + if ($dateactend > $now) $dateactend=$now; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - print '
'; - if ($objp->statut >= 4) - { - if ($objp->statut == 4) - { - print $langs->trans("DateEndReal").' '; - print $form->select_date($dateactend,"end",$usehm,$usehm,($objp->date_fin_reelle>0?0:1),"closeline",1,1,1); - } - } - print ''; - print '
'; + if ($objp->statut >= 4) + { + if ($objp->statut == 4) + { + print $langs->trans("DateEndReal").' '; + print $form->select_date($dateactend,"end",$usehm,$usehm,($objp->date_fin_reelle>0?0:1),"closeline",1,1,1); + } + } + print ''; + print '
'.$langs->trans("Comment").''; - print '   '; - print ''; - print '
'.$langs->trans("Comment").''; + print '   '; + print ''; + print '
'; + print ''; - print '
'; - } + print ''; + } - $cursorline++; - } + $cursorline++; + } // Form to add new line - if ($user->rights->contrat->creer && ($object->statut == 0)) - { - $dateSelector=1; + if ($user->rights->contrat->creer && ($object->statut == 0)) + { + $dateSelector=1; print "\n"; print '
@@ -1994,15 +1994,15 @@ else '; - print '
'; + print '
'; print ''; // Array with (n*2)+1 lines - // Trick to not show product entries - $savproductenabled=$conf->product->enabled; - if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $conf->product->enabled = 0; + // Trick to not show product entries + $savproductenabled=$conf->product->enabled; + if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) $conf->product->enabled = 0; - // Form to add new line - if ($action != 'editline') + // Form to add new line + if ($action != 'editline') { $var = true; @@ -2015,129 +2015,129 @@ else $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook } - // Restore correct setup - $conf->product->enabled = $savproductenabled; + // Restore correct setup + $conf->product->enabled = $savproductenabled; - print '
'; - print '
'; - print ''; - } + print ''; + print '
'; + print ''; + } dol_fiche_end(); - /* + /* * Buttons */ - if ($user->societe_id == 0) - { - print '
'; + if ($user->societe_id == 0) + { + print '
'; - $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + $parameters=array(); + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) - { - // Send - if ($object->statut == 1) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { - print ''; - } else - print ''; - } + if (empty($reshook)) + { + // Send + if ($object->statut == 1) { + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { + print ''; + } else + print ''; + } - if ($object->statut == 0 && $nbofservices) - { - if ($user->rights->contrat->creer) print ''; - else print ''; - } - if ($object->statut == 1) - { - if ($user->rights->contrat->creer) print ''; - else print ''; - } + if ($object->statut == 0 && $nbofservices) + { + if ($user->rights->contrat->creer) print ''; + else print ''; + } + if ($object->statut == 1) + { + if ($user->rights->contrat->creer) print ''; + else print ''; + } - if (! empty($conf->facture->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) - { - $langs->load("bills"); - if ($user->rights->facture->creer) print ''; - else print ''; - } + if (! empty($conf->facture->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) + { + $langs->load("bills"); + if ($user->rights->facture->creer) print ''; + else print ''; + } - if (! empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) - { - $langs->load("orders"); - if ($user->rights->commande->creer) print ''; - else print ''; - } + if (! empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) + { + $langs->load("orders"); + if ($user->rights->commande->creer) print ''; + else print ''; + } - // Clone - if ($user->rights->contrat->creer) { - print ''; - } + // Clone + if ($user->rights->contrat->creer) { + print ''; + } - if ($object->nbofservicesclosed > 0) - { - print ''; - } - if ($object->nbofservicesclosed < $nbofservices) - { - //if (! $numactive) - //{ - print ''; - //} - //else - //{ - // print ''; - //} - } + if ($object->nbofservicesclosed > 0) + { + print ''; + } + if ($object->nbofservicesclosed < $nbofservices) + { + //if (! $numactive) + //{ + print ''; + //} + //else + //{ + // print ''; + //} + } - // On peut supprimer entite si - // - Droit de creer + mode brouillon (erreur creation) - // - Droit de supprimer - if (($user->rights->contrat->creer && $object->statut == 0) || $user->rights->contrat->supprimer) - { - print ''; - } - else - { - print ''; - } - } + // On peut supprimer entite si + // - Droit de creer + mode brouillon (erreur creation) + // - Droit de supprimer + if (($user->rights->contrat->creer && $object->statut == 0) || $user->rights->contrat->supprimer) + { + print ''; + } + else + { + print ''; + } + } - print "
"; - } + print "
"; + } - // Select mail models is same action as presend - if (GETPOST('modelselected')) { - $action = 'presend'; - } + // Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } - if ($action != 'presend') - { - print '
'; + if ($action != 'presend') + { + print '
'; - /* + /* * Documents generes */ - $filename = dol_sanitizeFileName($object->ref); - $filedir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); - $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; - $genallowed = $user->rights->contrat->creer; - $delallowed = $user->rights->contrat->supprimer; + $filename = dol_sanitizeFileName($object->ref); + $filedir = $conf->contrat->dir_output . "/" . dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; + $genallowed = $user->rights->contrat->creer; + $delallowed = $user->rights->contrat->supprimer; - $var = true; + $var = true; - print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); + print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); - // Show links to link elements - $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat')); - $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat')); + $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - print '
'; + print '
'; // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; @@ -2145,8 +2145,8 @@ else $somethingshown = $formactions->showactions($object, 'contract', $socid, 1); - print '
'; - } + print '
'; + } // Presend form $modelmail='contract'; @@ -2155,7 +2155,7 @@ else $trackid = 'con'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; - } + } } diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index 66e37744cc7..d2082bfba01 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -267,22 +267,22 @@ class EmailSenderProfile extends CommonObject function getNomUrl($withpicto=0) { global $db, $conf, $langs; - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; - $result = ''; - $companylink = ''; + $result = ''; + $companylink = ''; - $url=''; - //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id; + $url=''; + //$url = dol_buildpath('/monmodule/emailsenderprofile_card.php',1).'?id='.$this->id; $linkstart = ''; $linkend=''; - if ($withpicto) - { - $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend); - if ($withpicto != 2) $result.=' '; + if ($withpicto) + { + $result.=($linkstart.img_object($label, 'label', 'class="classfortooltip"').$linkend); + if ($withpicto != 2) $result.=' '; } $result.= $linkstart . $this->label . $linkend; return $result; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 7559179c87d..f105ef78263 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -34,289 +34,289 @@ */ class FormFile { - private $db; + private $db; - public $error; - public $numoffiles; - public $infofiles; // Used to return informations by function getDocumentsLink + public $error; + public $numoffiles; + public $infofiles; // Used to return informations by function getDocumentsLink - /** + /** * Constructor * * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - $this->numoffiles=0; - return 1; - } + */ + function __construct($db) + { + $this->db = $db; + $this->numoffiles=0; + return 1; + } - /** - * Show form to upload a new file + /** + * Show form to upload a new file * - * @param string $url Url - * @param string $title Title zone (Title or '' or 'none') - * @param int $addcancel 1=Add 'Cancel' button - * @param int $sectionid If upload must be done inside a particular ECM section - * @param int $perm Value of permission to allow upload - * @param int $size Length of input file area. Deprecated. - * @param Object $object Object to use (when attachment is done on an element) - * @param string $options Add an option column - * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used. - * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' - * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files - * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) - * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*') - * @return int <0 if KO, >0 if OK - */ - function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='') - { - global $conf,$langs, $hookmanager; - $hookmanager->initHooks(array('formfile')); + * @param string $url Url + * @param string $title Title zone (Title or '' or 'none') + * @param int $addcancel 1=Add 'Cancel' button + * @param int $sectionid If upload must be done inside a particular ECM section + * @param int $perm Value of permission to allow upload + * @param int $size Length of input file area. Deprecated. + * @param Object $object Object to use (when attachment is done on an element) + * @param string $options Add an option column + * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used. + * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' + * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files + * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) + * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*') + * @return int <0 if KO, >0 if OK + */ + function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='') + { + global $conf,$langs, $hookmanager; + $hookmanager->initHooks(array('formfile')); - if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0; + if (! empty($conf->browser->layout) && $conf->browser->layout != 'classic') $useajax=0; if ((! empty($conf->global->MAIN_USE_JQUERY_FILEUPLOAD) && $useajax) || ($useajax==2)) - { - // TODO: Check this works with 2 forms on same page - // TODO: Check this works with GED module, otherwise, force useajax to 0 - // TODO: This does not support option savingdocmask - // TODO: This break feature to upload links too - return $this->_formAjaxFileUpload($object); - } - else - { - //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed - if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { - return 1; - } + { + // TODO: Check this works with 2 forms on same page + // TODO: Check this works with GED module, otherwise, force useajax to 0 + // TODO: This does not support option savingdocmask + // TODO: This break feature to upload links too + return $this->_formAjaxFileUpload($object); + } + else + { + //If there is no permission and the option to hide unauthorized actions is enabled, then nothing is printed + if (!$perm && !empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) { + return 1; + } - $maxlength=$size; + $maxlength=$size; - $out = "\n\n\n"; + $out = "\n\n\n"; - if (empty($title)) $title=$langs->trans("AttachANewFile"); - if ($title != 'none') $out.=load_fiche_titre($title, null, null); + if (empty($title)) $title=$langs->trans("AttachANewFile"); + if ($title != 'none') $out.=load_fiche_titre($title, null, null); - $out .= '
'; - $out .= ''; - $out .= ''; - $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= ''; - $out .= ''; - $out .= ''; + $out .= '
'; + $out .= ''; - if (! empty($options)) $out .= ''; + if (! empty($options)) $out .= ''; - $out .= '"; + if (! empty($conf->global->MAIN_UPLOAD_DOC)) + { + if ($perm) + { + $langs->load('other'); + $out .= ' '; + $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1); + } + } + else + { + $out .= ' ('.$langs->trans("UploadDisabled").')'; + } + $out .= ""; - if ($savingdocmask) - { - $out .= ''; - if (! empty($options)) $out .= ''; - $out .= ''; + if (! empty($options)) $out .= ''; + $out .= ''; - $out .= ''; - } + $out .= ''; + $out .= ''; + } - $out .= "
'.$options.''.$options.''; + $out .= ''; - $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb - $maxphp=@ini_get('upload_max_filesize'); // En inconnu - if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1; - if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024; - if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024; - if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024; - // Now $max and $maxphp are in Kb - if ($maxphp > 0) $max=min($max,$maxphp); + $max=$conf->global->MAIN_UPLOAD_DOC; // En Kb + $maxphp=@ini_get('upload_max_filesize'); // En inconnu + if (preg_match('/k$/i',$maxphp)) $maxphp=$maxphp*1; + if (preg_match('/m$/i',$maxphp)) $maxphp=$maxphp*1024; + if (preg_match('/g$/i',$maxphp)) $maxphp=$maxphp*1024*1024; + if (preg_match('/t$/i',$maxphp)) $maxphp=$maxphp*1024*1024*1024; + // Now $max and $maxphp are in Kb + if ($maxphp > 0) $max=min($max,$maxphp); - if ($max > 0) - { - $out .= ''; - } + if ($max > 0) + { + $out .= ''; + } - $out .= 'global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple'); - $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); - $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""'); - $out .= '>'; - $out .= ' '; - $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); - $out .= '>'; + $out .= 'global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple'); + $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); + $out .= (!empty($accept)?' accept="'.$accept.'"':' accept=""'); + $out .= '>'; + $out .= ' '; + $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); + $out .= '>'; - if ($addcancel) - { - $out .= '   '; - $out .= ''; - } + if ($addcancel) + { + $out .= '   '; + $out .= ''; + } - if (! empty($conf->global->MAIN_UPLOAD_DOC)) - { - if ($perm) - { - $langs->load('other'); - $out .= ' '; - $out .= info_admin($langs->trans("ThisLimitIsDefinedInSetup",$max,$maxphp),1); - } - } - else - { - $out .= ' ('.$langs->trans("UploadDisabled").')'; - } - $out .= "
'.$options.''; + if ($savingdocmask) + { + $out .= '
'.$options.''; $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); - $out .= '
"; + $out .= ""; - $out .= '
'; - if (empty($sectionid)) $out .= '
'; + $out .= ''; + if (empty($sectionid)) $out .= '
'; - $out .= "\n\n"; + $out .= "\n\n"; - if ($linkfiles) - { - $out .= "\n\n"; - $langs->load('link'); - $title = $langs->trans("LinkANewFile"); - $out .= load_fiche_titre($title, null, null); - $out .= '
'; - $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm); - $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object); + $out .= '
'; + $out .= '
'; + if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= ' '; + $out .= ''; + $out .= '
'; + $out .= '
'; + if (! empty($conf->global->OPTIMIZEFORTEXTBROWSER)) $out .= ' '; + $out .= ''; + $out .= ''; + $out .= ''; + $out .= '
'; + $out .= '
'; + $out .= 'global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); + $out .= '>'; + $out .= '
'; + $out .= '
'; + $out .= '
'; + $out .= '
'; + $parameters = array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''), 'url'=>$url, 'perm'=>$perm); + $res = $hookmanager->executeHooks('formattachOptions',$parameters,$object); - $out .= "\n\n"; - } + $out .= "\n\n"; + } - if (empty($res)) - { - print '
'; - print $out; - print '
'; - } + if (empty($res)) + { + print '
'; + print $out; + print '
'; + } - print $hookmanager->resPrint; + print $hookmanager->resPrint; - return 1; - } - } + return 1; + } + } - /** - * Show the box with list of available documents for object - * - * @param string $modulepart propal, facture, facture_fourn, ... - * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. - * @param string $filedir Directory to scan - * @param string $urlsource Url of origin page (for return) - * @param int $genallowed Generation is allowed (1/0 or array of formats) - * @param int $delallowed Remove is allowed (1/0) - * @param string $modelselected Model to preselect by default - * @param integer $allowgenifempty Show warning if no model activated - * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) - * @param int $iconPDF Show only PDF icon with link (1/0) - * @param int $notused Not used - * @param integer $noform Do not output html form tags - * @param string $param More param on http links - * @param string $title Title to show on top of form - * @param string $buttonlabel Label on submit button - * @param string $codelang Default language code to use on lang combo box if multilang is enabled - * @return int <0 if KO, number of shown files if OK - * @deprecated Use print xxx->showdocuments() instead. - */ - function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='') - { - $this->numoffiles=0; - print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang); - return $this->numoffiles; - } + /** + * Show the box with list of available documents for object + * + * @param string $modulepart propal, facture, facture_fourn, ... + * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. + * @param string $filedir Directory to scan + * @param string $urlsource Url of origin page (for return) + * @param int $genallowed Generation is allowed (1/0 or array of formats) + * @param int $delallowed Remove is allowed (1/0) + * @param string $modelselected Model to preselect by default + * @param integer $allowgenifempty Show warning if no model activated + * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) + * @param int $iconPDF Show only PDF icon with link (1/0) + * @param int $notused Not used + * @param integer $noform Do not output html form tags + * @param string $param More param on http links + * @param string $title Title to show on top of form + * @param string $buttonlabel Label on submit button + * @param string $codelang Default language code to use on lang combo box if multilang is enabled + * @return int <0 if KO, number of shown files if OK + * @deprecated Use print xxx->showdocuments() instead. + */ + function show_documents($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='') + { + $this->numoffiles=0; + print $this->showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed,$modelselected,$allowgenifempty,$forcenomultilang,$iconPDF,$notused,$noform,$param,$title,$buttonlabel,$codelang); + return $this->numoffiles; + } - /** - * Return a string to show the box with list of available documents for object. - * This also set the property $this->numoffiles - * - * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...) - * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. - * @param string $filedir Directory to scan - * @param string $urlsource Url of origin page (for return) - * @param int $genallowed Generation is allowed (1/0 or array list of templates) - * @param int $delallowed Remove is allowed (1/0) - * @param string $modelselected Model to preselect by default - * @param integer $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) - * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) - * @param int $iconPDF Deprecated, see getDocumentsLink - * @param int $notused Not used - * @param integer $noform Do not output html form tags - * @param string $param More param on http links - * @param string $title Title to show on top of form - * @param string $buttonlabel Label on submit button - * @param string $codelang Default language code to use on lang combo box if multilang is enabled - * @param string $morepicto Add more HTML content into cell with picto - * @param Object $object Object when method is called from an object card. - * @return string Output string with HTML array of documents (might be empty string) - */ - function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null) - { + /** + * Return a string to show the box with list of available documents for object. + * This also set the property $this->numoffiles + * + * @param string $modulepart Module the files are related to ('propal', 'facture', 'facture_fourn', 'mymodule', 'mymodule_temp', ...) + * @param string $modulesubdir Existing (so sanitized) sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. + * @param string $filedir Directory to scan + * @param string $urlsource Url of origin page (for return) + * @param int $genallowed Generation is allowed (1/0 or array list of templates) + * @param int $delallowed Remove is allowed (1/0) + * @param string $modelselected Model to preselect by default + * @param integer $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) + * @param integer $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) + * @param int $iconPDF Deprecated, see getDocumentsLink + * @param int $notused Not used + * @param integer $noform Do not output html form tags + * @param string $param More param on http links + * @param string $title Title to show on top of form + * @param string $buttonlabel Label on submit button + * @param string $codelang Default language code to use on lang combo box if multilang is enabled + * @param string $morepicto Add more HTML content into cell with picto + * @param Object $object Object when method is called from an object card. + * @return string Output string with HTML array of documents (might be empty string) + */ + function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$notused=0,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='',$object=null) + { // Deprecation warning if (0 !== $iconPDF) { dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING); } - global $langs, $conf, $user, $hookmanager; - global $form, $bc; + global $langs, $conf, $user, $hookmanager; + global $form, $bc; - if (! is_object($form)) $form=new Form($this->db); + if (! is_object($form)) $form=new Form($this->db); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - // For backward compatibility - if (! empty($iconPDF)) { - return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir); - } + // For backward compatibility + if (! empty($iconPDF)) { + return $this->getDocumentsLink($modulepart, $modulesubdir, $filedir); + } - $printer=0; - if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport'))) // The direct print feature is implemented only for such elements - { - $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false; - } + $printer=0; + if (in_array($modulepart,array('facture','supplier_proposal','propal','proposal','order','commande','expedition', 'commande_fournisseur', 'expensereport'))) // The direct print feature is implemented only for such elements + { + $printer = (!empty($user->rights->printing->read) && !empty($conf->printing->enabled))?true:false; + } - $hookmanager->initHooks(array('formfile')); - $forname='builddoc'; - $out=''; + $hookmanager->initHooks(array('formfile')); + $forname='builddoc'; + $out=''; - $headershown=0; - $showempty=0; - $i=0; + $headershown=0; + $showempty=0; + $i=0; - $out.= "\n".''."\n"; - //print 'filedir='.$filedir; + $out.= "\n".''."\n"; + //print 'filedir='.$filedir; - if (preg_match('/massfilesarea_/', $modulepart)) - { - $out.='

'."\n"; + if (preg_match('/massfilesarea_/', $modulepart)) + { + $out.='

'."\n"; $title=$langs->trans("MassFilesArea").' ('.$langs->trans("Hide").')'; $title.=''; - } + } - $titletoshow=$langs->trans("Documents"); - if (! empty($title)) $titletoshow=$title; + $titletoshow=$langs->trans("Documents"); + if (! empty($title)) $titletoshow=$title; - // Show table - if ($genallowed) - { - $modellist=array(); + // Show table + if ($genallowed) + { + $modellist=array(); - if ($modulepart == 'company') - { - $showempty=1; - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php'; - $modellist=ModeleThirdPartyDoc::liste_modeles($this->db); - } - } - else if ($modulepart == 'propal') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; - $modellist=ModelePDFPropales::liste_modeles($this->db); - } - } + if ($modulepart == 'company') + { + $showempty=1; + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php'; + $modellist=ModeleThirdPartyDoc::liste_modeles($this->db); + } + } + else if ($modulepart == 'propal') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php'; + $modellist=ModelePDFPropales::liste_modeles($this->db); + } + } else if ($modulepart == 'supplier_proposal') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php'; - $modellist=ModelePDFSupplierProposal::liste_modeles($this->db); - } - } - else if ($modulepart == 'commande') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; - $modellist=ModelePDFCommandes::liste_modeles($this->db); - } - } - elseif ($modulepart == 'expedition') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; - $modellist=ModelePDFExpedition::liste_modeles($this->db); - } - } - elseif ($modulepart == 'livraison') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; - $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db); - } - } - else if ($modulepart == 'ficheinter') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; - $modellist=ModelePDFFicheinter::liste_modeles($this->db); - } - } - elseif ($modulepart == 'facture') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; - $modellist=ModelePDFFactures::liste_modeles($this->db); - } - } - elseif ($modulepart == 'contract') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; - $modellist=ModelePDFContract::liste_modeles($this->db); - } - } - elseif ($modulepart == 'project') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; - $modellist=ModelePDFProjects::liste_modeles($this->db); - } - } - elseif ($modulepart == 'project_task') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php'; - $modellist=ModelePDFTask::liste_modeles($this->db); - } - } - elseif ($modulepart == 'product') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php'; - $modellist=ModelePDFProduct::liste_modeles($this->db); - } - } - elseif ($modulepart == 'export') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php'; - $modellist=ModeleExports::liste_modeles($this->db); - } - } - else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; - $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db); - } - } - else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; - $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db); - } - } + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_proposal/modules_supplier_proposal.php'; + $modellist=ModelePDFSupplierProposal::liste_modeles($this->db); + } + } + else if ($modulepart == 'commande') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; + $modellist=ModelePDFCommandes::liste_modeles($this->db); + } + } + elseif ($modulepart == 'expedition') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; + $modellist=ModelePDFExpedition::liste_modeles($this->db); + } + } + elseif ($modulepart == 'livraison') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/livraison/modules_livraison.php'; + $modellist=ModelePDFDeliveryOrder::liste_modeles($this->db); + } + } + else if ($modulepart == 'ficheinter') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php'; + $modellist=ModelePDFFicheinter::liste_modeles($this->db); + } + } + elseif ($modulepart == 'facture') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; + $modellist=ModelePDFFactures::liste_modeles($this->db); + } + } + elseif ($modulepart == 'contract') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; + $modellist=ModelePDFContract::liste_modeles($this->db); + } + } + elseif ($modulepart == 'project') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php'; + $modellist=ModelePDFProjects::liste_modeles($this->db); + } + } + elseif ($modulepart == 'project_task') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php'; + $modellist=ModelePDFTask::liste_modeles($this->db); + } + } + elseif ($modulepart == 'product') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/product/modules_product.class.php'; + $modellist=ModelePDFProduct::liste_modeles($this->db); + } + } + elseif ($modulepart == 'export') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/export/modules_export.php'; + $modellist=ModeleExports::liste_modeles($this->db); + } + } + else if ($modulepart == 'commande_fournisseur' || $modulepart == 'supplier_order') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; + $modellist=ModelePDFSuppliersOrders::liste_modeles($this->db); + } + } + else if ($modulepart == 'facture_fournisseur' || $modulepart == 'supplier_invoice') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; + $modellist=ModelePDFSuppliersInvoices::liste_modeles($this->db); + } + } else if ($modulepart == 'supplier_payment') { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php'; - $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db); - } - } - else if ($modulepart == 'remisecheque') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php'; - $modellist=ModeleChequeReceipts::liste_modeles($this->db); - } - } - elseif ($modulepart == 'donation') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; - $modellist=ModeleDon::liste_modeles($this->db); - } - } - elseif ($modulepart == 'member') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php'; - $modellist=ModelePDFCards::liste_modeles($this->db); - } - } - elseif ($modulepart == 'agenda') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php'; - $modellist=ModeleAction::liste_modeles($this->db); - } - } - else if ($modulepart == 'expensereport') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; - $modellist=ModeleExpenseReport::liste_modeles($this->db); - } - } - else if ($modulepart == 'unpaid') - { - $modellist=''; - } - elseif ($modulepart == 'user') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php'; - $modellist=ModelePDFUser::liste_modeles($this->db); - } - } - elseif ($modulepart == 'usergroup') - { - if (is_array($genallowed)) $modellist=$genallowed; - else - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php'; - $modellist=ModelePDFUserGroup::liste_modeles($this->db); - } - } - else //if ($modulepart != 'agenda') - { - // For normalized standard modules - $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); - if (file_exists($file)) - { - $res=include_once $file; - } - // For normalized external modules - else + if (is_array($genallowed)) $modellist=$genallowed; + else { - $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); - $res=include_once $file; - } - $class='Modele'.ucfirst($modulepart); - if (class_exists($class)) - { - $modellist=call_user_func($class.'::liste_modeles',$this->db); - } - else - { - dol_print_error($this->db,'Bad value for modulepart'); - return -1; - } - } + include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php'; + $modellist=ModelePDFSuppliersPayments::liste_modeles($this->db); + } + } + else if ($modulepart == 'remisecheque') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php'; + $modellist=ModeleChequeReceipts::liste_modeles($this->db); + } + } + elseif ($modulepart == 'donation') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/dons/modules_don.php'; + $modellist=ModeleDon::liste_modeles($this->db); + } + } + elseif ($modulepart == 'member') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_cards.php'; + $modellist=ModelePDFCards::liste_modeles($this->db); + } + } + elseif ($modulepart == 'agenda') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/action/modules_action.php'; + $modellist=ModeleAction::liste_modeles($this->db); + } + } + else if ($modulepart == 'expensereport') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php'; + $modellist=ModeleExpenseReport::liste_modeles($this->db); + } + } + else if ($modulepart == 'unpaid') + { + $modellist=''; + } + elseif ($modulepart == 'user') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/user/modules_user.class.php'; + $modellist=ModelePDFUser::liste_modeles($this->db); + } + } + elseif ($modulepart == 'usergroup') + { + if (is_array($genallowed)) $modellist=$genallowed; + else + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/usergroup/modules_usergroup.class.php'; + $modellist=ModelePDFUserGroup::liste_modeles($this->db); + } + } + else //if ($modulepart != 'agenda') + { + // For normalized standard modules + $file=dol_buildpath('/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); + if (file_exists($file)) + { + $res=include_once $file; + } + // For normalized external modules + else + { + $file=dol_buildpath('/'.$modulepart.'/core/modules/'.$modulepart.'/modules_'.$modulepart.'.php',0); + $res=include_once $file; + } + $class='Modele'.ucfirst($modulepart); + if (class_exists($class)) + { + $modellist=call_user_func($class.'::liste_modeles',$this->db); + } + else + { + dol_print_error($this->db,'Bad value for modulepart'); + return -1; + } + } - // Set headershown to avoit to have table opened a second time later - $headershown=1; + // Set headershown to avoit to have table opened a second time later + $headershown=1; - $buttonlabeltoshow=$buttonlabel; - if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); + $buttonlabeltoshow=$buttonlabel; + if (empty($buttonlabel)) $buttonlabel=$langs->trans('Generate'); - if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation - if (empty($noform)) $out.= '
'; - $out.= ''; - $out.= ''; + if ($conf->browser->layout == 'phone') $urlsource.='#'.$forname.'_form'; // So we switch to form after a generation + if (empty($noform)) $out.= ''; + $out.= ''; + $out.= ''; - $out.= load_fiche_titre($titletoshow, '', ''); - $out.= '
'; - $out.= ''; + $out.= load_fiche_titre($titletoshow, '', ''); + $out.= '
'; + $out.= '
'; - $out.= ''; + $out.= ''; - $addcolumforpicto=($delallowed || $printer || $morepicto); - $out.= ''; + // Button + $genbutton = 'dol_no_mouse_hover) && $modulepart != 'unpaid') + { + $langs->load("errors"); + $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); + } + if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton=''; + if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton=''; + $out.= $genbutton; + $out.= ''; - if (!empty($hookmanager->hooks['formfile'])) - { - foreach($hookmanager->hooks['formfile'] as $module) - { - if (method_exists($module, 'formBuilddocLineOptions')) $out .= ''; - } - } - $out.= ''; + if (!empty($hookmanager->hooks['formfile'])) + { + foreach($hookmanager->hooks['formfile'] as $module) + { + if (method_exists($module, 'formBuilddocLineOptions')) $out .= ''; + } + } + $out.= ''; - // Execute hooks - $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart); - if (is_object($hookmanager)) - { - $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']); - $out.= $hookmanager->resPrint; - } + // Execute hooks + $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart); + if (is_object($hookmanager)) + { + $reshook = $hookmanager->executeHooks('formBuilddocOptions',$parameters,$GLOBALS['object']); + $out.= $hookmanager->resPrint; + } - } + } - // Get list of files - if (! empty($filedir)) - { - $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC); + // Get list of files + if (! empty($filedir)) + { + $file_list=dol_dir_list($filedir,'files',0,'','(\.meta|_preview.*.*\.png)$','date',SORT_DESC); - $link_list = array(); - if (is_object($object)) - { - require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; - $link = new Link($this->db); - $sortfield = $sortorder = null; - $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder); - } + $link_list = array(); + if (is_object($object)) + { + require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php'; + $link = new Link($this->db); + $sortfield = $sortorder = null; + $res = $link->fetchAll($link_list, $object->element, $object->id, $sortfield, $sortorder); + } - $out.= ''."\n"; + $out.= ''."\n"; - // Show title of array if not already shown - if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart)) && ! $headershown) - { - $headershown=1; - $out.= '
'.$titletoshow.'
'."\n"; - $out.= '
'; - $out.= '
'; + $addcolumforpicto=($delallowed || $printer || $morepicto); + $out.= ''; - // Model - if (! empty($modellist)) - { - $out.= ''.$langs->trans('Model').' '; - if (is_array($modellist) && count($modellist) == 1) // If there is only one element - { - $arraykeys=array_keys($modellist); - $modelselected=$arraykeys[0]; - } - $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100'); - $out.= ajax_combobox('model'); - } - else - { - $out.= '
'.$langs->trans("Files").'
'; - } + // Model + if (! empty($modellist)) + { + $out.= ''.$langs->trans('Model').' '; + if (is_array($modellist) && count($modellist) == 1) // If there is only one element + { + $arraykeys=array_keys($modellist); + $modelselected=$arraykeys[0]; + } + $out.= $form->selectarray('model', $modellist, $modelselected, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth100'); + $out.= ajax_combobox('model'); + } + else + { + $out.= '
'.$langs->trans("Files").'
'; + } - // Language code (if multilang) - if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; - $formadmin=new FormAdmin($this->db); - $defaultlang=$codelang?$codelang:$langs->getDefaultLang(); - $morecss='maxwidth150'; - if (! empty($conf->browser->phone)) $morecss='maxwidth100'; - $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss); - } - else - { - $out.= ' '; - } + // Language code (if multilang) + if (($allowgenifempty || (is_array($modellist) && count($modellist) > 0)) && $conf->global->MAIN_MULTILANGS && ! $forcenomultilang && (! empty($modellist) || $showempty)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; + $formadmin=new FormAdmin($this->db); + $defaultlang=$codelang?$codelang:$langs->getDefaultLang(); + $morecss='maxwidth150'; + if (! empty($conf->browser->phone)) $morecss='maxwidth100'; + $out.= $formadmin->select_language($defaultlang, 'lang_id', 0, 0, 0, 0, 0, $morecss); + } + else + { + $out.= ' '; + } - // Button - $genbutton = 'dol_no_mouse_hover) && $modulepart != 'unpaid') - { - $langs->load("errors"); - $genbutton.= ' '.img_warning($langs->transnoentitiesnoconv("WarningNoDocumentModelActivated")); - } - if (! $allowgenifempty && ! is_array($modellist) && empty($modellist) && empty($conf->dol_no_mouse_hover) && $modulepart != 'unpaid') $genbutton=''; - if (empty($modellist) && ! $showempty && $modulepart != 'unpaid') $genbutton=''; - $out.= $genbutton; - $out.= '
'."\n"; - } + // Show title of array if not already shown + if ((! empty($file_list) || ! empty($link_list) || preg_match('/^massfilesarea/', $modulepart)) && ! $headershown) + { + $headershown=1; + $out.= '
'.$titletoshow.'
'."\n"; + $out.= '
'; + $out.= '
'."\n"; + } - // Loop on each file found + // Loop on each file found if (is_array($file_list)) { foreach($file_list as $file) { // Define relative path for download link (depends on module) $relativepath=$file["name"]; // Cas general - if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... + if ($modulesubdir) $relativepath=$modulesubdir."/".$file["name"]; // Cas propal, facture... if ($modulepart == 'export') $relativepath = $file["name"]; // Other case $out.= ''; @@ -713,8 +713,8 @@ class FormFile // Show file name with link to download $out.= ''; - } + $out.=''; + } - if (is_object($hookmanager)) - { - $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath); - $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file); - if (empty($res)) - { - $out .= $hookmanager->resPrint; // Complete line - $out.= ''; - } - else $out = $hookmanager->resPrint; // Replace line - } + if (is_object($hookmanager)) + { + $parameters=array('socid'=>(isset($GLOBALS['socid'])?$GLOBALS['socid']:''),'id'=>(isset($GLOBALS['id'])?$GLOBALS['id']:''),'modulepart'=>$modulepart,'relativepath'=>$relativepath); + $res = $hookmanager->executeHooks('formBuilddocLineOptions',$parameters,$file); + if (empty($res)) + { + $out .= $hookmanager->resPrint; // Complete line + $out.= ''; + } + else $out = $hookmanager->resPrint; // Replace line + } } - $this->numoffiles++; - } - // Loop on each file found - if (is_array($link_list)) - { - $colspan=2; + $this->numoffiles++; + } + // Loop on each file found + if (is_array($link_list)) + { + $colspan=2; - foreach($link_list as $file) - { - $out.=''; - $out.=''; - $out.=''; - if ($delallowed || $printer || $morepicto) $out.=''; - $out.=''."\n"; - } - $this->numoffiles++; - } + foreach($link_list as $file) + { + $out.=''; + $out.=''; + $out.=''; + if ($delallowed || $printer || $morepicto) $out.=''; + $out.=''."\n"; + } + $this->numoffiles++; + } if (count($file_list) == 0 && count($link_list) == 0 && $headershown) - { - $out.=''."\n"; - } + { + $out.=''."\n"; + } - } + } - if ($headershown) - { - // Affiche pied du tableau - $out.= "
'; - $tmp = $this->showPreview($file,$modulepart,$relativepath,0,$param); - $out.= ($tmp?$tmp.' ':''); + $tmp = $this->showPreview($file,$modulepart,$relativepath,0,$param); + $out.= ($tmp?$tmp.' ':''); $out.= 'trans("PrintFile", $relativepath),'printer.png').''; + $out.= ' '.img_picto($langs->trans("PrintFile", $relativepath),'printer.png').''; } if ($morepicto) { $morepicto=preg_replace('/__FILENAMEURLENCODED__/',urlencode($relativepath),$morepicto); - $out.=$morepicto; + $out.=$morepicto; } - $out.='
'; - $out.=''; - $out.=$file->label; - $out.=''; - $out.=''; - $out.=dol_print_date($file->datea,'dayhour'); - $out.='
'; + $out.=''; + $out.=$file->label; + $out.=''; + $out.=''; + $out.=dol_print_date($file->datea,'dayhour'); + $out.='
'.$langs->trans("None").'
'.$langs->trans("None").'
\n"; - $out.= "
\n"; - if ($genallowed) - { - if (empty($noform)) $out.= '
'."\n"; - } - } - $out.= ''."\n"; - //return ($i?$i:$headershown); - return $out; - } + if ($headershown) + { + // Affiche pied du tableau + $out.= "\n"; + $out.= "
\n"; + if ($genallowed) + { + if (empty($noform)) $out.= ''."\n"; + } + } + $out.= ''."\n"; + //return ($i?$i:$headershown); + return $out; + } - /** - * Show a Document icon with link(s) - * You may want to call this into a div like this: - * print '
'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
'; - * - * @param string $modulepart propal, facture, facture_fourn, ... - * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. - * @param string $filedir Full path to directory to scan - * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') - * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles - */ - function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='') - { - global $conf, $langs; + /** + * Show a Document icon with link(s) + * You may want to call this into a div like this: + * print '
'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'
'; + * + * @param string $modulepart propal, facture, facture_fourn, ... + * @param string $modulesubdir Sub-directory to scan (Example: '0/1/10', 'FA/DD/MM/YY/9999'). Use '' if file is not into subdir of module. + * @param string $filedir Full path to directory to scan + * @param string $filter Filter filenames on this regex string (Example: '\.pdf$') + * @return string Output string with HTML link of documents (might be empty string). This also fill the array ->infofiles + */ + function getDocumentsLink($modulepart, $modulesubdir, $filedir, $filter='') + { + global $conf, $langs; - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $out=''; - $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array()); + $out=''; + $this->infofiles=array('nboffiles'=>0,'extensions'=>array(),'files'=>array()); - $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+'; + $filterforfilesearch = preg_quote(basename($modulesubdir),'/').'[^\-]+'; - $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files) + $file_list=dol_dir_list($filedir, 'files', 0, $filterforfilesearch, '\.meta$|\.png$'); // Get list of files starting with name of ref (but not followed by "-" to discard uploaded files) - // For ajax treatment + // For ajax treatment $out.= ''."\n"; - if (! empty($file_list)) - { - $out='