From 467dc12a7bc9ec4f5d044e55c94ebbf22940a26b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 25 Jan 2016 12:33:38 +0100 Subject: [PATCH] NEW Module "Supplier commercial proposal" (price request) is set to stable status. --- htdocs/comm/propal.php | 6 +-- .../comm/propal/class/propalestats.class.php | 44 +++++++++++++---- htdocs/comm/propal/stats/index.php | 27 ++++++++-- htdocs/commande/card.php | 15 +++--- htdocs/commande/stats/index.php | 4 +- htdocs/core/class/commonobject.class.php | 10 ++-- htdocs/core/class/html.form.class.php | 7 ++- htdocs/core/menus/init_menu_auguria.sql | 1 + htdocs/core/menus/standard/eldy.lib.php | 2 + .../modules/modSupplierProposal.class.php | 21 ++++++-- htdocs/fourn/commande/card.php | 34 +++++++------ .../mysql/tables/llx_supplier_proposal.sql | 2 +- .../install/mysql/tables/llx_website.key.sql | 23 +++++++++ htdocs/langs/en_US/propal.lang | 3 +- htdocs/supplier_proposal/card.php | 41 ++++++++++------ .../class/supplier_proposal.class.php | 49 +++++++++++-------- 16 files changed, 197 insertions(+), 92 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_website.key.sql diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index e039342dd38..aed5ee01a5d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2116,7 +2116,7 @@ if ($action == 'create') $form_close .= $object->note; $form_close .= ''; $form_close .= ''; - $form_close .= ''; + $form_close .= ''; $form_close .= '   '; $form_close .= ' '; $form_close .= ''; @@ -2204,10 +2204,10 @@ if ($action == 'create') } } - // Close + // Set accepted/refused if ($object->statut == Propal::STATUS_VALIDATED && $user->rights->propal->cloturer) { print '
global->MAIN_JUMP_TAG) ? '' : '#close') . '"'; - print '>' . $langs->trans('Close') . '
'; + print '>' . $langs->trans('SetAcceptedRefused') . ''; } // Clone diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index 07a5ff606bc..11014537337 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -26,6 +26,7 @@ include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; include_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; +include_once DOL_DOCUMENT_ROOT . '/supplier_proposal/class/supplier_proposal.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; @@ -50,8 +51,9 @@ class PropaleStats extends Stats * @param DoliDB $db Database handler * @param int $socid Id third party for filter. This value must be forced during the new to external user company if user is an external user. * @param int $userid Id user for filter (creation user) + * @param string $mode Option ('customer', 'supplier') */ - function __construct($db, $socid=0, $userid=0) + function __construct($db, $socid=0, $userid=0, $mode='customer') { global $user, $conf; @@ -59,15 +61,37 @@ class PropaleStats extends Stats $this->socid = ($socid > 0 ? $socid : 0); $this->userid = $userid; - $object=new Propal($this->db); - - $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; - $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; - - $this->field='total_ht'; - $this->field_line='total_ht'; - - $this->where.= " p.fk_statut > 0"; + if ($mode == 'customer') + { + $object=new Propal($this->db); + + $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; + $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; + + $this->field='total_ht'; + $this->field_line='total_ht'; + + $this->where.= " p.fk_statut > 0"; + } + if ($mode == 'supplier') + { + $object=new SupplierProposal($this->db); + + $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; + $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; + + $this->field='total_ht'; + $this->field_line='total_ht'; + + $this->where.= " p.fk_statut > 0"; + + $object=new CommandeFournisseur($this->db); + $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; + $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; + $this->field='total_ht'; + $this->field_line='total_ht'; + $this->where.= " c.fk_statut > 2"; // Only approved & ordered + } //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; $this->where.= " AND p.entity IN (".getEntity('propal', 1).")"; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index 5ff5723a6c0..2f4c2ee342f 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -33,6 +33,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php'; $WIDTH=DolGraph::getDefaultGraphSizeForStats('width'); $HEIGHT=DolGraph::getDefaultGraphSizeForStats('height'); +$mode=GETPOST("mode")?GETPOST("mode"):'customer'; +if ($mode == 'customer' && ! $user->rights->propale->lire) accessforbidden(); +if ($mode == 'supplier' && ! $user->rights->supplier_proposal->lire) accessforbidden(); + $object_statut=GETPOST('propal_statut'); $userid=GETPOST('userid','int'); @@ -50,7 +54,10 @@ $year = GETPOST('year')>0?GETPOST('year'):$nowyear; $startyear=$year-1; $endyear=$year; -$mode=GETPOST('mode'); +$langs->load('orders'); +$langs->load('companies'); +$langs->load('other'); +$langs->load('suppliers'); /* @@ -64,16 +71,26 @@ $langs->load('propal'); $langs->load('other'); $langs->load("companies"); -llxHeader('', $langs->trans("ProposalsStatistics")); +if ($mode == 'customer') +{ + $title=$langs->trans("ProposalsStatistics"); + $dir=$conf->propale->dir_temp; +} +if ($mode == 'supplier') +{ + $title=$langs->trans("ProposalsStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")"; + $dir=$conf->supplier_proposal->dir_temp; +} -print load_fiche_titre($langs->trans("ProposalsStatistics"),'','title_commercial.png'); +llxHeader('', $title); + +print load_fiche_titre($title,'','title_commercial.png'); -$dir=$conf->propal->dir_temp; dol_mkdir($dir); -$stats = new PropaleStats($db, $socid, ($userid>0?$userid:0)); +$stats = new PropaleStats($db, $socid, ($userid>0?$userid:0), $mode); if ($object_statut != '' && $object_statut >= 0) $stats->where .= ' AND p.fk_statut IN ('.$object_statut.')'; // Build graphic number of object diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 9e7f5fae4f8..a152b005ee8 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -261,6 +261,13 @@ if (empty($reshook)) $object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + // Fill array 'array_options' with data from add form + if (! $error) + { + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; + } + // If creation from another object of another module (Example: origin=propal, originid=1) if (! empty($origin) && ! empty($originid)) { @@ -293,10 +300,6 @@ if (empty($reshook)) $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects); } - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error++; - if (! $error) { $object_id = $object->create($user); @@ -386,10 +389,6 @@ if (empty($reshook)) $action = 'create'; } } else { - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error++; - if (! $error) { $object_id = $object->create($user); diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index bf0331f251d..2bd1a592ba8 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -64,8 +64,6 @@ $langs->load('suppliers'); $form=new Form($db); -llxHeader(); - if ($mode == 'customer') { $title=$langs->trans("OrdersStatistics"); @@ -77,6 +75,8 @@ if ($mode == 'supplier') $dir=$conf->fournisseur->dir_output.'/commande/temp'; } +llxHeader('', $title); + print load_fiche_titre($title,'','title_commercial.png'); dol_mkdir($dir); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d1fa0b20448..005f4684322 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2384,14 +2384,14 @@ abstract class CommonObject { // Parse element/subelement (ex: project_task) $module = $element = $subelement = $objecttype; - if ($objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) + if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' + && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) { $module = $element = $regs[1]; $subelement = $regs[2]; } $classpath = $element.'/class'; - // To work with non standard classpath or module name if ($objecttype == 'facture') { $classpath = 'compta/facture/class'; @@ -2427,7 +2427,10 @@ abstract class CommonObject else if ($objecttype == 'order_supplier') { $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; } - + else if ($objecttype == 'supplier_proposal') { + $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; + } + // Here $module, $classfile and $classname are set if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { @@ -2595,6 +2598,7 @@ abstract class CommonObject $error = 0; $trigkey=''; + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 71c33a97e8c..6e1251e8703 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4967,13 +4967,13 @@ class Form { $tplpath = $element = $subelement = $objecttype; - if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) + if ($objecttype != 'supplier_proposal' && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) { $element = $regs[1]; $subelement = $regs[2]; $tplpath = $element.'/'.$subelement; } - + // To work with non standard path if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; @@ -4984,7 +4984,6 @@ class Form if (empty($conf->propal->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'supplier_proposal') { - $tplpath = 'comm/'.$element; if (empty($conf->supplier_proposal->enabled)) continue; // Do not show if module disabled } else if ($objecttype == 'shipping' || $objecttype == 'shipment') { @@ -5001,7 +5000,7 @@ class Form else if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } - + global $linkedObjectBlock; $linkedObjectBlock = $objects; diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index 912b432174e..b54e9a560ac 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -162,6 +162,7 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->ficheinter->enabled', __HANDLER__, 'left', 1500__+MAX_llx_menu__, 'commercial', 'ficheinter', 5__+MAX_llx_menu__, '/fichinter/list.php?leftmenu=ficheinter', 'Interventions', 0, 'interventions', '$user->rights->ficheinter->lire', '', 2, 8, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->ficheinter->enabled', __HANDLER__, 'left', 1501__+MAX_llx_menu__, 'commercial', '', 1500__+MAX_llx_menu__, '/fichinter/card.php?action=create&leftmenu=ficheinter', 'NewIntervention', 1, 'interventions', '$user->rights->ficheinter->creer', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->ficheinter->enabled', __HANDLER__, 'left', 1502__+MAX_llx_menu__, 'commercial', '', 1500__+MAX_llx_menu__, '/fichinter/list.php?leftmenu=ficheinter', 'List', 1, 'interventions', '$user->rights->ficheinter->lire', '', 2, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->ficheinter->enabled', __HANDLER__, 'left', 1503__+MAX_llx_menu__, 'commercial', '', 1500__+MAX_llx_menu__, '/fichinter/stats/index.php?leftmenu=ficheinter', 'Statistics', 1, 'interventions', '$user->rights->ficheinter->lire', '', 2, 2, __ENTITY__); -- Accountancy - Supplier invoice insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1600__+MAX_llx_menu__, 'accountancy', 'supplier_bills', 6__+MAX_llx_menu__, '/fourn/facture/list.php?leftmenu=suppliers_bills', 'BillsSuppliers', 0, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1601__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/fourn/facture/card.php?action=create&leftmenu=suppliers_bills', 'NewBill', 1, 'bills', '$user->rights->fournisseur->facture->creer', '', 2, 0, __ENTITY__); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index ce8b166197b..d8649bc8e34 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -771,6 +771,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/fichinter/index.php?leftmenu=ficheinter", $langs->trans("Interventions"), 0, $user->rights->ficheinter->lire, '', $mainmenu, 'ficheinter', 2200); $newmenu->add("/fichinter/card.php?action=create&leftmenu=ficheinter", $langs->trans("NewIntervention"), 1, $user->rights->ficheinter->creer, '', '', '', 201); $newmenu->add("/fichinter/list.php?leftmenu=ficheinter", $langs->trans("List"), 1, $user->rights->ficheinter->lire, '', '', '', 202); + + $newmenu->add("/fichinter/stats/index.php?leftmenu=ficheinter", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire); } } diff --git a/htdocs/core/modules/modSupplierProposal.class.php b/htdocs/core/modules/modSupplierProposal.class.php index 692cf2aefab..855ffde0ecf 100644 --- a/htdocs/core/modules/modSupplierProposal.class.php +++ b/htdocs/core/modules/modSupplierProposal.class.php @@ -52,7 +52,7 @@ class modSupplierProposal extends DolibarrModules $this->name = preg_replace('/^mod/i','',get_class($this)); $this->description = "supplier_proposalDESC"; - $this->version = 'experimental'; + $this->version = 'dolibarr'; $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); $this->special = 0; @@ -114,15 +114,13 @@ class modSupplierProposal extends DolibarrModules $this->rights[$r][0] = $this->numero + $r; // id de la permission $this->rights[$r][1] = 'Validate supplier proposals'; // libelle de la permission $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut - $this->rights[$r][4] = ''; - $this->rights[$r][5] = 'validate'; + $this->rights[$r][4] = 'validate_advance'; $r++; $this->rights[$r][0] = $this->numero + $r; // id de la permission $this->rights[$r][1] = 'Envoyer les demandes fournisseurs'; // libelle de la permission $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut - $this->rights[$r][4] = ''; - $this->rights[$r][5] = 'send_advance'; + $this->rights[$r][4] = 'send_advance'; $r++; $this->rights[$r][0] = $this->numero + $r; // id de la permission @@ -178,6 +176,19 @@ class modSupplierProposal extends DolibarrModules 'position'=>302 ); $r++; + + $this->menu[$r]=array( + 'fk_menu'=>'fk_mainmenu=commercial,fk_leftmenu=supplier_proposalsubmenu', + 'type'=>'left', + 'titre'=>'Statistics', + 'url'=>'/comm/propal/stats/index.php?leftmenu=propals&mode=supplier', + 'langs'=>'supplier_proposal', + 'enabled'=>'$conf->supplier_proposal->enabled', + 'perms'=>'$user->rights->supplier_proposal->lire', + 'user'=>2, + 'position'=>303 + ); + $r++; } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 3b1fa498336..45bbb2c21cc 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -954,12 +954,12 @@ if (empty($reshook)) $object->linked_objects = array_merge($object->linked_objects, $other_linked_objects); } - $object_id = $object->create($user); - if ($object_id > 0) + $id = $object->create($user); + if ($id > 0) { dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - $classname = ucfirst($subelement); + $classname = 'SupplierProposal'; $srcobject = new $classname($db); dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines"); @@ -980,7 +980,7 @@ if (empty($reshook)) $num = count($lines); $productsupplier = new ProductFournisseur($db); - + for($i = 0; $i < $num; $i ++) { @@ -995,7 +995,7 @@ if (empty($reshook)) if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) { $fk_parent_line = 0; } - + // Extrafields if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if // trigger used @@ -1003,10 +1003,13 @@ if (empty($reshook)) $lines[$i]->fetch_optionals($lines[$i]->rowid); $array_option = $lines[$i]->array_options; } - - $idprod = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty); - $res = $productsupplier->fetch($idProductFourn); - + + $res = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty); + /*if ($productsupplier->id > 0) + { + $res = $productsupplier->fetch($productsupplier->id); + }*/ + $result = $object->addline( $desc, $lines[$i]->subprice, @@ -1030,7 +1033,7 @@ if (empty($reshook)) ); if ($result < 0) { - $error ++; + $error++; break; } @@ -1040,10 +1043,13 @@ if (empty($reshook)) } } + // Add link between elements + + // 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 { @@ -1459,7 +1465,7 @@ if ($action=='create') dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); - $classname = ucfirst($subelement); + $classname = 'SupplierProposal'; $objectsrc = new $classname($db); $objectsrc->fetch($originid); if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) @@ -1604,8 +1610,6 @@ if ($action=='create') print ''; $newclassname = $classname; - if ($newclassname == 'SupplierProposal') - $newclassname = 'CommercialSupplierProposal'; print '' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . ''; print '' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . ''; print '' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva) . ""; @@ -2830,7 +2834,7 @@ elseif (! empty($object->id)) // Linked object block $somethingshown = $form->showLinkedObjectBlock($object); - + // Show links to link elements //$linktoelem = $form->showLinkToObjectBlock($object); //if ($linktoelem) print '
'.$linktoelem; diff --git a/htdocs/install/mysql/tables/llx_supplier_proposal.sql b/htdocs/install/mysql/tables/llx_supplier_proposal.sql index ef307b85c9f..cb0324a3ad4 100644 --- a/htdocs/install/mysql/tables/llx_supplier_proposal.sql +++ b/htdocs/install/mysql/tables/llx_supplier_proposal.sql @@ -31,7 +31,7 @@ CREATE TABLE llx_supplier_proposal ( fk_user_modif integer DEFAULT NULL, fk_user_valid integer DEFAULT NULL, fk_user_cloture integer DEFAULT NULL, - fk_statut smallint NOT NULL DEFAULT '0', + fk_statut smallint NOT NULL DEFAULT '0', -- 0=draft, 1=validated, 2=accepted, 3=refused price double DEFAULT '0', remise_percent double DEFAULT '0', remise_absolue double DEFAULT '0', diff --git a/htdocs/install/mysql/tables/llx_website.key.sql b/htdocs/install/mysql/tables/llx_website.key.sql new file mode 100644 index 00000000000..cdaa38079b3 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_website.key.sql @@ -0,0 +1,23 @@ +-- ============================================================================ +-- Copyright (C) 2016 Laurent Destailleur +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =========================================================================== + +ALTER TABLE llx_website_page ADD UNIQUE INDEX uk_website_page_url (fk_website,pageurl); + +ALTER TABLE llx_website_page ADD CONSTRAINT fk_website_page_website FOREIGN KEY (fk_website) REFERENCES llx_website (rowid); + + diff --git a/htdocs/langs/en_US/propal.lang b/htdocs/langs/en_US/propal.lang index f78ac37601c..e93af58f26b 100644 --- a/htdocs/langs/en_US/propal.lang +++ b/htdocs/langs/en_US/propal.lang @@ -63,7 +63,8 @@ DatePropal=Date of proposal DateEndPropal=Validity ending date DateEndPropalShort=Date end ValidityDuration=Validity duration -CloseAs=Close with status +CloseAs=Set status to +SetAcceptedRefused=Set accepted/refused ClassifyBilled=Classify billed BuildBill=Build invoice ErrorPropalNotFound=Propal %s not found diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 2a64fa5d4c5..82eeb323a36 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin @@ -45,6 +45,7 @@ $langs->load('companies'); $langs->load('supplier_proposal'); $langs->load('compta'); $langs->load('bills'); +$langs->load('propal'); $langs->load('orders'); $langs->load('products'); $langs->load("deliveries"); @@ -173,7 +174,7 @@ if (empty($reshook)) // Validation else if ($action == 'confirm_validate' && $confirm == 'yes' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate))) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance))) ) { $result = $object->valid($user); @@ -434,6 +435,14 @@ if (empty($reshook)) } // Close proposal + else if ($action == 'close' && $user->rights->supplier_proposal->cloturer && ! GETPOST('cancel')) { + // prevent browser refresh from reopening proposal several times + if ($object->statut == 2) { + $object->setStatut(4); + } + } + + // Set accepted/refused else if ($action == 'setstatut' && $user->rights->supplier_proposal->cloturer && ! GETPOST('cancel')) { if (! GETPOST('statut')) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CloseAs")), null, 'errors'); @@ -441,7 +450,7 @@ if (empty($reshook)) } else { // prevent browser refresh from closing proposal several times if ($object->statut == 1) { - $object->cloture($user, GETPOST('statut'), GETPOST('note')); + $object->cloture($user, GETPOST('statut'), GETPOST('note')); } } } @@ -1596,11 +1605,9 @@ if ($action == 'create') if ($action == 'statut') { - /* - * Form to close proposal (signed or not) - */ + // Form to set proposal accepted/refused $form_close = '
'; - $form_close .= '

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

'; + if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) $form_close .= '

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

'; // TODO Suggest a permanent checkbox instead of option $form_close .= ''; $form_close .= ''; $form_close .= ''; $form_close .= ''; $form_close .= '
' . $langs->trans("CloseAs") . ''; @@ -1615,9 +1622,9 @@ if ($action == 'create') $form_close .= $object->note; $form_close .= '
'; - $form_close .= ''; + $form_close .= ''; $form_close .= '   '; - $form_close .= ' '; + $form_close .= ' '; $form_close .= '
'; @@ -1640,7 +1647,7 @@ if ($action == 'create') // Validate if ($object->statut == 0 && $object->total_ttc >= 0 && count($object->lines) > 0 && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate))) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance))) ) { if (count($object->lines) > 0) print ''; @@ -1660,7 +1667,7 @@ if ($action == 'create') // Send if ($object->statut == 1 || $object->statut == 2) { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->supplier_proposal->send) { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->supplier_proposal->send_advance) { print ''; } else print ''; @@ -1673,12 +1680,18 @@ if ($action == 'create') } } - // Close + // Set accepted/refused if ($object->statut == 1 && $user->rights->supplier_proposal->cloturer) { - print ''; + print ''; } + // Close + if ($object->statut == 2 && $user->rights->supplier_proposal->cloturer) { + print ''; + } + // Clone if ($user->rights->supplier_proposal->creer) { print ''; diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 54a578a1e61..97f52526e66 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -27,7 +27,7 @@ */ /** - * \file htdocs/supplier_proposal/class/supplier_propal.class.php + * \file htdocs/supplier_proposal/class/supplier_proposal.class.php * \brief File of class to manage supplier proposals */ @@ -151,16 +151,16 @@ class SupplierProposal extends CommonObject $this->remise_absolue = 0; $langs->load("supplier_proposal"); - $this->labelstatut[0]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_DRAFT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_DRAFT_LABEL : $langs->trans("SupplierProposalStatusDraft")); - $this->labelstatut[1]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_VALIDATED_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_VALIDATED_LABEL : $langs->trans("SupplierProposalStatusValidated")); - $this->labelstatut[2]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_SIGNED_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_SIGNED_LABEL : $langs->trans("SupplierProposalStatusSigned")); - $this->labelstatut[3]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_NOTSIGNED_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_NOTSIGNED_LABEL : $langs->trans("SupplierProposalStatusNotSigned")); - $this->labelstatut[4]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_BILLED_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_BILLED_LABEL : $langs->trans("SupplierProposalStatusBilled")); - $this->labelstatut_short[0]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_DRAFTSHORT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_DRAFTSHORT_LABEL : $langs->trans("SupplierProposalStatusDraftShort")); - $this->labelstatut_short[1]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_VALIDATEDSHORT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_VALIDATEDSHORT_LABEL : $langs->trans("Opened")); - $this->labelstatut_short[2]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_SIGNEDSHORT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_SIGNEDSHORT_LABEL : $langs->trans("SupplierProposalStatusSignedShort")); - $this->labelstatut_short[3]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_NOTSIGNEDSHORT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_NOTSIGNEDSHORT_LABEL : $langs->trans("SupplierProposalStatusNotSignedShort")); - $this->labelstatut_short[4]=(! empty($conf->global->SUPPLIER_PROPOSAL_STATUS_BILLEDSHORT_LABEL) ? $conf->global->SUPPLIER_PROPOSAL_STATUS_BILLEDSHORT_LABEL : $langs->trans("SupplierProposalStatusBilledShort")); + $this->labelstatut[0]=$langs->trans("SupplierProposalStatusDraft"); + $this->labelstatut[1]=$langs->trans("SupplierProposalStatusValidated"); + $this->labelstatut[2]=$langs->trans("SupplierProposalStatusSigned"); + $this->labelstatut[3]=$langs->trans("SupplierProposalStatusNotSigned"); + $this->labelstatut[4]=$langs->trans("SupplierProposalStatusClosed"); + $this->labelstatut_short[0]=$langs->trans("SupplierProposalStatusDraftShort"); + $this->labelstatut_short[1]=$langs->trans("Opened"); + $this->labelstatut_short[2]=$langs->trans("SupplierProposalStatusSignedShort"); + $this->labelstatut_short[3]=$langs->trans("SupplierProposalStatusNotSignedShort"); + $this->labelstatut_short[4]=$langs->trans("SupplierProposalStatusClosedShort"); } @@ -1257,7 +1257,7 @@ class SupplierProposal extends CommonObject $now=dol_now(); if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate))) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->supplier_proposal->validate_advance))) { $this->db->begin(); @@ -1545,7 +1545,7 @@ class SupplierProposal extends CommonObject $soc=new Societe($this->db); $soc->id = $this->socid; $result=$soc->set_as_client(); - + if ($result < 0) { $this->error=$this->db->error(); @@ -1554,14 +1554,17 @@ class SupplierProposal extends CommonObject } else { - $this->updateOrCreatePriceFournisseur($user); + if (! empty($conf->global->SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL)) // TODO This option was not tested correctly. Error if product ref does not exists + { + $result = $this->updateOrCreatePriceFournisseur($user); + } } } if ($statut == 4) { $trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED'; } - + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language @@ -1594,25 +1597,27 @@ class SupplierProposal extends CommonObject } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); + $this->errors[]=$this->db->lasterror(); $this->db->rollback(); return -1; } } /** - * Choose between update or create ProductFournisseur + * Add or update supplier price according to result of proposal * - * @param User $user Object user + * @param User $user Object user + * @return int > 0 if OK */ function updateOrCreatePriceFournisseur($user) { $productsupplier = new ProductFournisseur($this->db); dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG); - foreach ($this->lines as $product) { - if ($product->subprice <= 0) - continue; + foreach ($this->lines as $product) + { + if ($product->subprice <= 0) continue; $idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty); $res = $productsupplier->fetch($idProductFourn); @@ -1627,6 +1632,8 @@ class SupplierProposal extends CommonObject $this->createPriceFournisseur($product, $user); } } + + return 1; } /**