diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index ce87f507cc6..3bdeb742650 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -407,7 +407,7 @@ $tabcond[14]= (! empty($conf->product->enabled) && ! empty($conf->ecotax->enable $tabcond[15]= true; $tabcond[16]= (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)); $tabcond[17]= (! empty($conf->deplacement->enabled) || ! empty($conf->expensereport->enabled)); -$tabcond[18]= ! empty($conf->expedition->enabled); +$tabcond[18]= ! empty($conf->expedition->enabled) || ! empty($conf->reception->enabled); $tabcond[19]= ! empty($conf->societe->enabled); $tabcond[20]= ! empty($conf->fournisseur->enabled); $tabcond[21]= ! empty($conf->propal->enabled); diff --git a/htdocs/admin/mails_templates.php b/htdocs/admin/mails_templates.php index aae1b5db470..70e0ae268ba 100644 --- a/htdocs/admin/mails_templates.php +++ b/htdocs/admin/mails_templates.php @@ -148,6 +148,7 @@ if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSen if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder'); if ($conf->facture->enabled) $elementList['facture_send']=$langs->trans('MailToSendInvoice'); if ($conf->expedition->enabled) $elementList['shipping_send']=$langs->trans('MailToSendShipment'); +if ($conf->reception->enabled) $elementList['reception_send']=$langs->trans('MailToSendReception'); if ($conf->ficheinter->enabled) $elementList['fichinter_send']=$langs->trans('MailToSendIntervention'); if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send']=$langs->trans('MailToSendSupplierRequestForQuotation'); if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$langs->trans('MailToSendSupplierOrder'); diff --git a/htdocs/admin/reception_extrafields.php b/htdocs/admin/reception_extrafields.php new file mode 100644 index 00000000000..dbfccb60773 --- /dev/null +++ b/htdocs/admin/reception_extrafields.php @@ -0,0 +1,127 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2012 Florian Henry + * Copyright (C) 2013 Philippe Grand + * Copyright (C) 2015 Claudio Aschieri + * Copyright (C) 2018 Quentin Vial-Gouteyron + * + * 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 . + */ + +/** + * \file htdocs/admin/reception_extrafields.php + * \ingroup reception + * \brief Page to setup extra fields of reception + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + + +if (!$user->admin) + accessforbidden(); + +$langs->load("admin"); +$langs->load("other"); +$langs->load("receptions"); +$langs->load("deliveries"); + + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='reception'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("Receptions"); + +llxHeader('',$langs->trans("ReceptionsSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ReceptionsSetup"),$linkback,'title_setup'); +print "
\n"; + +$head = reception_admin_prepare_head(); + +dol_fiche_head($head, 'attributes_reception', $langs->trans("Receptions"), -1, 'sending'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation of an optional field */ +/* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print "
"; + print load_fiche_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition of an optional field */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print "
"; + print load_fiche_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/admin/reception_setup.php b/htdocs/admin/reception_setup.php index 710c1fb6ba1..4aa362932af 100644 --- a/htdocs/admin/reception_setup.php +++ b/htdocs/admin/reception_setup.php @@ -205,7 +205,7 @@ print load_fiche_titre($langs->trans("ReceptionsSetup"),$linkback,'title_setup') print '
'; $head = reception_admin_prepare_head(); -dol_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'reception'); +dol_fiche_head($head, 'reception', $langs->trans("Receptions"), -1, 'sending'); // Reception numbering model diff --git a/htdocs/admin/receptiondet_extrafields.php b/htdocs/admin/receptiondet_extrafields.php new file mode 100644 index 00000000000..80bc3806b52 --- /dev/null +++ b/htdocs/admin/receptiondet_extrafields.php @@ -0,0 +1,127 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2012 Florian Henry + * Copyright (C) 2013 Philippe Grand + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2015 Claudio Aschieri + * Copyright (C) 2018 Quentin Vial-Gouteyron + * + * + * 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 . + */ + +/** + * \file htdocs/admin/receptiondet_extrafields.php + * \ingroup reception + * \brief Page to setup extra fields of reception + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + + +if (!$user->admin) + accessforbidden(); + +$langs->load("admin"); +$langs->load("other"); +$langs->load("receptions"); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='receptiondet'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject=$langs->transnoentitiesnoconv("Receptions"); + +llxHeader('',$langs->trans("ReceptionsSetup")); + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ReceptionsSetup"),$linkback,'title_setup'); +print "
\n"; + +$head = reception_admin_prepare_head(); + +dol_fiche_head($head, 'attributeslines_reception', $langs->trans("Receptions"), -1, 'sending'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation of an optional field */ +/* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print "
"; + print load_fiche_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition of an optional field */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print "
"; + print load_fiche_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 36a4ec697e6..cc77ea99e1a 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -74,16 +74,22 @@ if($action) // Mode of stock increase if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL' || $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER' - || $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') + || $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER' + || $action == 'STOCK_CALCULATE_ON_RECEPTION' + || $action == 'STOCK_CALCULATE_ON_RECEPTION_CLOSE') { //Use variable cause empty(GETPOST()) do not work with php version < 5.4 $valdispatch=GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity); + $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_RECEPTION", '','chaine',0,'',$conf->entity); + $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_RECEPTION_CLOSE", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity); + if ($action == 'STOCK_CALCULATE_ON_RECEPTION') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_RECEPTION", GETPOST('STOCK_CALCULATE_ON_RECEPTION','alpha'),'chaine',0,'',$conf->entity); + if ($action == 'STOCK_CALCULATE_ON_RECEPTION_CLOSE') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_RECEPTION_CLOSE", GETPOST('STOCK_CALCULATE_ON_RECEPTION_CLOSE','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $valdispatch,'chaine',0,'',$conf->entity); if (empty($valdispatch)) { $res=dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", '','chaine',0,'',$conf->entity); @@ -107,6 +113,9 @@ if($action) if($action == 'STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT') { $res = dolibarr_set_const($db, "STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", GETPOST('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT','alpha'),'chaine',0,'',$conf->entity); } + if($action == 'STOCK_MUST_BE_ENOUGH_FOR_RECEPTION') { + $res = dolibarr_set_const($db, "STOCK_MUST_BE_ENOUGH_FOR_RECEPTION", GETPOST('STOCK_MUST_BE_ENOUGH_FOR_RECEPTION','alpha'),'chaine',0,'',$conf->entity); + } if($action == 'INDEPENDANT_SUBPRODUCT_STOCK') { $res = dolibarr_set_const($db, "INDEPENDANT_SUBPRODUCT_STOCK", GETPOST('INDEPENDANT_SUBPRODUCT_STOCK','alpha'),'chaine',0,'',$conf->entity); } @@ -307,25 +316,58 @@ else print "\n\n"; $found++; - -print ''; -print ''.$langs->trans("ReStockOnDispatchOrder").''; -print ''; -if (! empty($conf->fournisseur->enabled)) +if (!empty($conf->reception->enabled)) { - print "
"; + print ''; + print ''.$langs->trans("StockOnReception").''; + print ''; + + print ""; print ''; - print ""; - print $form->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER",$conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER,1,$disabled); + print ""; + print $form->selectyesno("STOCK_CALCULATE_ON_RECEPTION", $conf->global->STOCK_CALCULATE_ON_RECEPTION, 1, $disabled); print ''; print "
\n"; + + print "\n\n"; + $found++; + + + print ''; + print ''.$langs->trans("StockOnReceptionOnClosing").''; + print ''; + + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE, 1, $disabled); + print ''; + print "
\n"; + + print "\n\n"; + $found++; } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + print ''; + print ''.$langs->trans("ReStockOnDispatchOrder").''; + print ''; + if (!empty($conf->fournisseur->enabled)) + { + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER, 1, $disabled); + print ''; + print "
\n"; + } + else + { + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + } + print "\n\n"; + $found++; } -print "\n\n"; -$found++; /*if (! $found) { @@ -402,6 +444,20 @@ if($conf->expedition->enabled) { print "\n"; print "\n"; } +if($conf->reception->enabled) { + $var = !$var; + print ''; + print ''.$langs->trans("StockMustBeEnoughForReception").''; + print ''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_RECEPTION",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_RECEPTION,1); + print ''; + print '
'; + print "\n"; + print "\n"; +} print ''; $virtualdiffersfromphysical=0; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index da44eeeb6f6..8e37bee0218 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -415,7 +415,11 @@ class Conf $this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE=0; $this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL=0; $this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER=0; - $this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER=1; + if(empty($this->reception->enabled))$this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER=1; + else { + $this->global->STOCK_CALCULATE_ON_RECEPTION=1; + $this->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE=0; + } } // conf->currency diff --git a/htdocs/core/lib/fourn.lib.php b/htdocs/core/lib/fourn.lib.php index 44e7774cae6..7be7bbea94e 100644 --- a/htdocs/core/lib/fourn.lib.php +++ b/htdocs/core/lib/fourn.lib.php @@ -111,7 +111,7 @@ function ordersupplier_prepare_head($object) $head[$h][2] = 'card'; $h++; - if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) + if (! empty($conf->stock->enabled) && (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { $langs->load("stocks"); $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index a3ce8ba52df..48e533b93d5 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2623,8 +2623,10 @@ elseif (! empty($object->id)) } // Ship - if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) + + if (! empty($conf->stock->enabled) && (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE))) { + if (in_array($object->statut, array(3,4))) { if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->receptionner) { print ''; diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql b/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql index 789ec3e7a9b..074dc0d4c16 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseur_dispatch.sql @@ -25,6 +25,7 @@ create table llx_commande_fournisseur_dispatch fk_commande integer, fk_product integer, fk_commandefourndet integer, + fk_projet integer DEFAULT NULL, qty float, -- qty fk_entrepot integer, fk_user integer, diff --git a/htdocs/install/mysql/tables/llx_reception.key.sql b/htdocs/install/mysql/tables/llx_reception.key.sql index 736945193ff..a107c2a7d12 100644 --- a/htdocs/install/mysql/tables/llx_reception.key.sql +++ b/htdocs/install/mysql/tables/llx_reception.key.sql @@ -18,14 +18,14 @@ -- =================================================================== -ALTER TABLE llx_expedition ADD UNIQUE INDEX idx_expedition_uk_ref (ref, entity); +ALTER TABLE llx_reception ADD UNIQUE INDEX idx_reception_uk_ref (ref, entity); -ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_soc (fk_soc); -ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_author (fk_user_author); -ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_user_valid (fk_user_valid); -ALTER TABLE llx_expedition ADD INDEX idx_expedition_fk_shipping_method (fk_shipping_method); +ALTER TABLE llx_reception ADD INDEX idx_reception_fk_soc (fk_soc); +ALTER TABLE llx_reception ADD INDEX idx_reception_fk_user_author (fk_user_author); +ALTER TABLE llx_reception ADD INDEX idx_reception_fk_user_valid (fk_user_valid); +ALTER TABLE llx_reception ADD INDEX idx_reception_fk_shipping_method (fk_shipping_method); -ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); -ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); -ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_user_valid FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid); -ALTER TABLE llx_expedition ADD CONSTRAINT fk_expedition_fk_shipping_method FOREIGN KEY (fk_shipping_method) REFERENCES llx_c_shipment_mode (rowid); +ALTER TABLE llx_reception ADD CONSTRAINT fk_reception_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); +ALTER TABLE llx_reception ADD CONSTRAINT fk_reception_fk_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); +ALTER TABLE llx_reception ADD CONSTRAINT fk_reception_fk_user_valid FOREIGN KEY (fk_user_valid) REFERENCES llx_user (rowid); +ALTER TABLE llx_reception ADD CONSTRAINT fk_reception_fk_shipping_method FOREIGN KEY (fk_shipping_method) REFERENCES llx_c_shipment_mode (rowid); diff --git a/htdocs/install/mysql/tables/llx_reception.sql b/htdocs/install/mysql/tables/llx_reception.sql index 088e4893c06..34565f7f29a 100644 --- a/htdocs/install/mysql/tables/llx_reception.sql +++ b/htdocs/install/mysql/tables/llx_reception.sql @@ -19,7 +19,7 @@ -- -- =================================================================== -create table llx_expedition +create table llx_reception ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, @@ -30,7 +30,7 @@ create table llx_expedition ref_ext varchar(30), -- reference into an external system (not used by dolibarr) ref_int varchar(30), -- reference into an internal system (used by dolibarr to store extern id like paypal info) - ref_customer varchar(30), -- customer number + ref_supplier varchar(30), -- customer number date_creation datetime, -- date de creation fk_user_author integer, -- author of creation @@ -38,8 +38,7 @@ create table llx_expedition date_valid datetime, -- date de validation fk_user_valid integer, -- valideur date_delivery datetime DEFAULT NULL, -- date planned of delivery - date_expedition datetime, -- not used (deprecated) - fk_address integer DEFAULT NULL, -- delivery address (deprecated) + date_reception datetime, fk_shipping_method integer, tracking_number varchar(50), fk_statut smallint DEFAULT 0, -- 0 = draft, 1 = validated, 2 = billed or closed depending on WORKFLOW_BILL_ON_SHIPMENT option diff --git a/htdocs/install/mysql/tables/llx_reception_extrafields.key.sql b/htdocs/install/mysql/tables/llx_reception_extrafields.key.sql index b539f460a08..f3a35acd8a3 100644 --- a/htdocs/install/mysql/tables/llx_reception_extrafields.key.sql +++ b/htdocs/install/mysql/tables/llx_reception_extrafields.key.sql @@ -17,4 +17,4 @@ -- =================================================================== -ALTER TABLE llx_expedition_extrafields ADD INDEX idx_expedition_extrafields (fk_object); +ALTER TABLE llx_reception_extrafields ADD INDEX idx_reception_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_reception_extrafields.sql b/htdocs/install/mysql/tables/llx_reception_extrafields.sql index eff8465fbf6..7a3126b2015 100644 --- a/htdocs/install/mysql/tables/llx_reception_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_reception_extrafields.sql @@ -16,7 +16,7 @@ -- -- ======================================================================== -create table llx_expedition_extrafields +create table llx_reception_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, diff --git a/htdocs/install/mysql/tables/llx_receptiondet.key.sql b/htdocs/install/mysql/tables/llx_receptiondet.key.sql index 5f5b6a08183..3740f83d1d0 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet.key.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet.key.sql @@ -18,5 +18,5 @@ -- =================================================================== -ALTER TABLE llx_expeditiondet ADD INDEX idx_expeditiondet_fk_expedition (fk_expedition); -ALTER TABLE llx_expeditiondet ADD CONSTRAINT fk_expeditiondet_fk_expedition FOREIGN KEY (fk_expedition) REFERENCES llx_expedition (rowid); +ALTER TABLE llx_receptiondet ADD INDEX idx_receptiondet_fk_reception (fk_reception); +ALTER TABLE llx_receptiondet ADD CONSTRAINT fk_receptiondet_fk_reception FOREIGN KEY (fk_reception) REFERENCES llx_reception (rowid); diff --git a/htdocs/install/mysql/tables/llx_receptiondet.sql b/htdocs/install/mysql/tables/llx_receptiondet.sql index bd05bd08898..dd726c85eab 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet.sql @@ -18,10 +18,10 @@ -- -- =================================================================== -create table llx_expeditiondet +create table llx_receptiondet ( rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_expedition integer NOT NULL, + fk_reception integer NOT NULL, fk_origin_line integer, -- Correspondance de la ligne avec le document d'origine (propal, commande) fk_entrepot integer, -- Entrepot de depart du produit qty real, -- Quantity diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql index 70bfe974f34..59928d1c278 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.key.sql @@ -16,5 +16,5 @@ -- -- ============================================================================ -ALTER TABLE llx_expeditiondet_batch ADD INDEX idx_fk_expeditiondet (fk_expeditiondet); -ALTER TABLE llx_expeditiondet_batch ADD CONSTRAINT fk_expeditiondet_batch_fk_expeditiondet FOREIGN KEY (fk_expeditiondet) REFERENCES llx_expeditiondet(rowid); +ALTER TABLE llx_receptiondet_batch ADD INDEX idx_fk_receptiondet (fk_receptiondet); +ALTER TABLE llx_receptiondet_batch ADD CONSTRAINT fk_receptiondet_batch_fk_receptiondet FOREIGN KEY (fk_receptiondet) REFERENCES llx_receptiondet(rowid); diff --git a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql index 2a1234d9342..ef2537cc116 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_batch.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_batch.sql @@ -15,9 +15,9 @@ -- along with this program. If not, see . -- -- ============================================================================ -CREATE TABLE llx_expeditiondet_batch ( +CREATE TABLE llx_receptiondet_batch ( rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_expeditiondet int NOT NULL, + fk_receptiondet int NOT NULL, eatby date DEFAULT NULL, sellby date DEFAULT NULL, batch varchar(30) DEFAULT NULL, diff --git a/htdocs/install/mysql/tables/llx_receptiondet_extrafields.key.sql b/htdocs/install/mysql/tables/llx_receptiondet_extrafields.key.sql index 11e133442d5..5d5d52b5526 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_extrafields.key.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_extrafields.key.sql @@ -17,4 +17,4 @@ -- =================================================================== -ALTER TABLE llx_expeditiondet_extrafields ADD INDEX idx_expeditiondet_extrafields (fk_object); +ALTER TABLE llx_receptiondet_extrafields ADD INDEX idx_receptiondet_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_receptiondet_extrafields.sql b/htdocs/install/mysql/tables/llx_receptiondet_extrafields.sql index e27c7f3e505..5fe823efd76 100644 --- a/htdocs/install/mysql/tables/llx_receptiondet_extrafields.sql +++ b/htdocs/install/mysql/tables/llx_receptiondet_extrafields.sql @@ -16,7 +16,7 @@ -- -- =================================================================== -create table llx_expeditiondet_extrafields +create table llx_receptiondet_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index bfe6e81858c..e72d093d543 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -1439,11 +1439,9 @@ SendingsAbility=Prise en charge des bons d'expédition pour les livraisons clien NoNeedForDeliveryReceipts=Dans le plupart des cas, la fiche expédition est utilisée en tant que bon d'expédition (liste des produits expédiés) et bon de livraison (signée par le client). Le bon de réception est un doublon de fonctionnalité et est rarement utilisé. FreeLegalTextOnShippings=Mention complémentaire sur les expéditions ##### Reception ##### -ReceptionsSetup=Configuration du module Réception/Livraison +ReceptionsSetup=Configuration du module Réception ReceptionsReceiptModel=Modèles de bordereau de réception ReceptionsNumberingModules=Modèles de numérotation des réceptions -ReceptionsAbility=Prise en charge des bons d'réception pour les livraisons clients -NoNeedForDeliveryReceipts=Dans le plupart des cas, la fiche réception est utilisée en tant que bon d'réception (liste des produits expédiés) et bon de livraison (signée par le client). Le bon de réception est un doublon de fonctionnalité et est rarement utilisé. FreeLegalTextOnShippings=Mention complémentaire sur les réceptions ##### Deliveries ##### DeliveryOrderNumberingModules=Modèle de numérotation des bons de réception client diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 9a79bf2f8bd..2fb7d558d8e 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -60,6 +60,8 @@ DeStockOnBill=Décrémente les stocks physiques sur validation des factures/avoi DeStockOnValidateOrder=Décrémente les stocks physiques sur validation des commandes clients DeStockOnShipment=Décrémenter les stocks physiques sur validation des expéditions DeStockOnShipmentOnClosing=Décrémenter les stocks réels au classement "clôturée" de l'expédition +StockOnReception=Incrémenter les stocks physiques sur validation des réceptions +StockOnReceptionOnClosing=Incrémenter les stocks réels au classement "clôturée" de la réception ReStockOnBill=Incrémente les stocks physiques sur validation des factures/avoirs fournisseurs ReStockOnValidateOrder=Incrémente les stocks physiques sur approbation des commandes fournisseurs ReStockOnDispatchOrder=Incrémente les stocks réels sur ventilation manuelle dans les entrepôts, après réception de la marchandise @@ -123,9 +125,10 @@ RecordMovement=Enregistrer transfert ReceivingForSameOrder=Réceptions pour cette commande StockMovementRecorded=Mouvement de stocks enregistré RuleForStockAvailability=Règles d'exigence sur les stocks -StockMustBeEnoughForInvoice=Le niveau de stock doit être suffisant pour ajouter ce produit/service à la facture (la vérification est faite sur le stock réel lors de l'ajout de la ligne de facture, quelquesoit la règle de modification automatique de stock) -StockMustBeEnoughForOrder=Le niveau de stock doit être suffisant pour ajouter ce produit/service à la commande (la vérification est faite sur le stock réel lors de l'ajout de la ligne de commande, quelquesoit la règle de modification automatique de stock) -StockMustBeEnoughForShipment= Le niveau de stock doit être suffisant pour ajouter ce produit/service à l'expédition (la vérification est faite sur le stock réel lors de l'ajout de la ligne à l'expédition, quelquesoit la règle de modification automatique de stock) +StockMustBeEnoughForInvoice=Le niveau de stock doit être suffisant pour ajouter ce produit/service à la facture (la vérification est faite sur le stock réel lors de l'ajout de la ligne de facture, quel que soit la règle de modification automatique de stock) +StockMustBeEnoughForOrder=Le niveau de stock doit être suffisant pour ajouter ce produit/service à la commande (la vérification est faite sur le stock réel lors de l'ajout de la ligne de commande, quel que soit la règle de modification automatique de stock) +StockMustBeEnoughForShipment= Le niveau de stock doit être suffisant pour ajouter ce produit/service à l'expédition (la vérification est faite sur le stock réel lors de l'ajout de la ligne à l'expédition, quel que soit la règle de modification automatique de stock) +StockMustBeEnoughForReception= Le niveau de stock doit être suffisant pour ajouter ce produit/service à la réception (la vérification est faite sur le stock réel lors de l'ajout de la ligne à la récepetion, quel que soit la règle de modification automatique de stock) MovementLabel=Libellé du mouvement InventoryCode=Code mouvement ou inventaire IsInPackage=Inclus dans un package diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 05adfc1b5c5..e11a1665866 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3839,6 +3839,9 @@ class Product extends CommonObject $this->stock_theorique=$this->stock_reel-$stock_commande_client; } // Stock Increase mode + if (! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) { + $this->stock_theorique+=$stock_commande_fournisseur-$stock_reception_fournisseur; + } if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) { $this->stock_theorique+=$stock_commande_fournisseur-$stock_reception_fournisseur; } diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 5561d5778f6..3cd0b459f13 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -121,7 +121,7 @@ else $result=restrictedArea($user,'produit|service','','','','','',$objcanvas); // Define virtualdiffersfromphysical $virtualdiffersfromphysical=0; -if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) ) { $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. } diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index e3983344cff..f5d8e358a66 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -75,7 +75,7 @@ if (! empty($canvas)) // Define virtualdiffersfromphysical $virtualdiffersfromphysical=0; -if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)|| ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) { $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index f45f2b30a56..bf07fa244d2 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -638,6 +638,8 @@ if ($id > 0 || $ref) $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)?$langs->trans("ReStockOnBill").'
':''); $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)?$langs->trans("ReStockOnValidateOrder").'
':''); $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)?$langs->trans("ReStockOnDispatchOrder").'
':''); + $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || ! empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)?$langs->trans("StockOnReception").'
':''); + print ''; print $form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1); print ''; diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 28786f0d324..fe74df5e35e 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -80,7 +80,9 @@ if (!$sortorder) { $virtualdiffersfromphysical=0; if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) -|| ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) +|| ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) +|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) +|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) { $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. } diff --git a/htdocs/product/stock/replenishorders.php b/htdocs/product/stock/replenishorders.php index 694f9cae1ad..3763dc2e8fc 100644 --- a/htdocs/product/stock/replenishorders.php +++ b/htdocs/product/stock/replenishorders.php @@ -113,7 +113,7 @@ $sql.= ' WHERE cf.fk_soc = s.rowid '; $sql.= ' AND cf.entity = ' . $conf->entity; if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) { $sql .= ' AND cf.fk_statut < 3'; -} elseif ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) { +} elseif ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER|| !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) { $sql .= ' AND cf.fk_statut < 6'; // We want also status 5, we will keep them visible if dispatching is not yet finished (tested with function dolDispatchToDo). } else { $sql .= ' AND cf.fk_statut < 5'; diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 324714fee7c..5aabccb8347 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -51,7 +51,7 @@ class Reception extends CommonObject public $picto = 'reception'; var $socid; - var $ref_customer; + var $ref_supplier; var $ref_int; var $brouillon; var $entrepot_id; @@ -201,7 +201,7 @@ class Reception extends CommonObject $sql = "INSERT INTO ".MAIN_DB_PREFIX."reception ("; $sql.= "ref"; $sql.= ", entity"; - $sql.= ", ref_customer"; + $sql.= ", ref_supplier"; $sql.= ", ref_int"; $sql.= ", date_creation"; $sql.= ", fk_user_author"; @@ -210,7 +210,7 @@ class Reception extends CommonObject $sql.= ", fk_soc"; $sql.= ", fk_projet"; $sql.= ", fk_address"; - $sql.= ", fk_reception_method"; + $sql.= ", fk_shipping_method"; $sql.= ", tracking_number"; $sql.= ", weight"; $sql.= ", size"; @@ -225,7 +225,7 @@ class Reception extends CommonObject $sql.= ") VALUES ("; $sql.= "'(PROV)'"; $sql.= ", ".$conf->entity; - $sql.= ", ".($this->ref_customer?"'".$this->db->escape($this->ref_customer)."'":"null"); + $sql.= ", ".($this->ref_supplier?"'".$this->db->escape($this->ref_supplier)."'":"null"); $sql.= ", ".($this->ref_int?"'".$this->db->escape($this->ref_int)."'":"null"); $sql.= ", '".$this->db->idate($now)."'"; $sql.= ", ".$user->id; @@ -477,10 +477,10 @@ class Reception extends CommonObject // Check parameters if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; - $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut"; + $sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut"; $sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; $sql.= ", e.date_reception as date_reception, e.model_pdf, e.fk_address, e.date_delivery"; - $sql.= ", e.fk_reception_method, e.tracking_number"; + $sql.= ", e.fk_shipping_method, e.tracking_number"; $sql.= ", el.fk_source as origin_id, el.sourcetype as origin"; $sql.= ", e.note_private, e.note_public"; $sql.= ', e.fk_incoterms, e.location_incoterms'; @@ -505,7 +505,7 @@ class Reception extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->ref; $this->socid = $obj->socid; - $this->ref_customer = $obj->ref_customer; + $this->ref_supplier = $obj->ref_supplier; $this->ref_ext = $obj->ref_ext; $this->ref_int = $obj->ref_int; $this->statut = $obj->fk_statut; @@ -517,7 +517,7 @@ class Reception extends CommonObject $this->date_delivery = $this->db->jdate($obj->date_delivery); // Date planed $this->fk_delivery_address = $obj->fk_address; $this->modelpdf = $obj->model_pdf; - $this->reception_method_id = $obj->fk_reception_method; + $this->shipping_method_id = $obj->fk_shipping_method; $this->tracking_number = $obj->tracking_number; $this->origin = ($obj->origin?$obj->origin:'commande'); // For compatibility $this->origin_id = $obj->origin_id; @@ -1007,7 +1007,7 @@ class Reception extends CommonObject if (isset($this->ref)) $this->ref=trim($this->ref); if (isset($this->entity)) $this->entity=trim($this->entity); - if (isset($this->ref_customer)) $this->ref_customer=trim($this->ref_customer); + if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier); if (isset($this->socid)) $this->socid=trim($this->socid); if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid); @@ -1035,7 +1035,7 @@ class Reception extends CommonObject $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; - $sql.= " ref_customer=".(isset($this->ref_customer)?"'".$this->db->escape($this->ref_customer)."'":"null").","; + $sql.= " ref_supplier=".(isset($this->ref_supplier)?"'".$this->db->escape($this->ref_supplier)."'":"null").","; $sql.= " fk_soc=".(isset($this->socid)?$this->socid:"null").","; $sql.= " date_creation=".(dol_strlen($this->date_creation)!=0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').","; $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").","; @@ -1044,7 +1044,7 @@ class Reception extends CommonObject $sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').","; $sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').","; $sql.= " fk_address=".(isset($this->fk_delivery_address)?$this->fk_delivery_address:"null").","; - $sql.= " fk_reception_method=".((isset($this->reception_method_id) && $this->reception_method_id > 0)?$this->reception_method_id:"null").","; + $sql.= " fk_shipping_method=".((isset($this->reception_method_id) && $this->reception_method_id > 0)?$this->reception_method_id:"null").","; $sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").","; $sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").","; $sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").","; @@ -1498,7 +1498,7 @@ class Reception extends CommonObject $result=''; $label = '' . $langs->trans("ShowReception") . ''; $label .= '
' . $langs->trans('Ref') . ': '.$this->ref; - $label .= '
'.$langs->trans('RefCustomer').': '.($this->ref_customer ? $this->ref_customer : $this->ref_client); + $label .= '
'.$langs->trans('RefCustomer').': '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client); $url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id; diff --git a/scripts/reception/create-table.php b/scripts/reception/create-table.php new file mode 100644 index 00000000000..a9f3401f327 --- /dev/null +++ b/scripts/reception/create-table.php @@ -0,0 +1,278 @@ + '--') + { + $buf = preg_replace('/--(.+)*/', '', $buf); + $buffer .= $buf; + } + } + fclose($fp); + + $buffer = trim($buffer); + if ($conf->db->type == 'mysql' || $conf->db->type == 'mysqli') // For Mysql 5.5+, we must replace type=innodb with ENGINE=innodb + { + $buffer = preg_replace('/type=innodb/i', 'ENGINE=innodb', $buffer); + } + else if ($conf->db->type == 'mssql') + { + $buffer = preg_replace('/type=innodb/i', '', $buffer); + $buffer = preg_replace('/ENGINE=innodb/i', '', $buffer); + } + + // Replace the prefix tables + if ($dolibarr_main_db_prefix != 'llx_') + { + $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); + } + + //print "Creation de la table $name/td>"; + $requestnb++; + + $resql = $db->query($buffer, 0, 'dml'); + if ($resql) + { + // print "OK requete ==== $buffer"; + $db->free($resql); + } + else + { + if ($db->errno() == 'DB_ERROR_TABLE_ALREADY_EXISTS' || + $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS') + { + //print "Deja existante"; + } + else + { + print "".$langs->trans("CreateTableAndPrimaryKey", $name); + print "
\n".$langs->trans("Request").' '.$requestnb.' : '.$buffer.'
Executed query : '.$db->lastquery; + print "\n"; + print ''.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().''; + $error++; + } + } + } + else + { + print "".$langs->trans("CreateTableAndPrimaryKey", $name); + print ""; + print ''.$langs->trans("Error").' Failed to open file '.$dir.$file.''; + $error++; + } +} + +if ($tablefound) +{ + if ($error == 0) + { + print ''; + print $langs->trans("TablesAndPrimaryKeysCreation").'Ok'; + $ok = 1; + } +} +else +{ + print ''.$langs->trans("ErrorFailedToFindSomeFiles", $dir).'Error'; +} + + + +// We always choose in mysql directory (Conversion is done by driver to translate SQL syntax) + + +$okkeys = 0; +$handle = opendir($dir); +$tablefound = 0; +$tabledata = array(); +if (is_resource($handle)) +{ + while (($file = readdir($handle)) !== false) + { + if (preg_match('/\.sql$/i', $file) && preg_match('/^llx_/i', $file) && preg_match('/\.key\.sql$/i', $file)) + { + if (strpos($file, 'reception') !== false){ + $tablefound++; + $tabledata[] = $file; + } + } + } + closedir($handle); +} + +// Sort list of sql files on alphabetical order (load order is important) +sort($tabledata); +foreach ($tabledata as $file) +{ + $name = substr($file, 0, dol_strlen($file) - 4); + //print "Creation de la table $name"; + $buffer = ''; + $fp = fopen($dir.$file, "r"); + if ($fp) + { + while (!feof($fp)) + { + $buf = fgets($fp, 4096); + + // Cas special de lignes autorisees pour certaines versions uniquement + if ($choix == 1 && preg_match('/^--\sV([0-9\.]+)/i', $buf, $reg)) + { + $versioncommande = explode('.', $reg[1]); + //print var_dump($versioncommande); + //print var_dump($versionarray); + if (count($versioncommande) && count($versionarray) && versioncompare($versioncommande, $versionarray) <= 0) + { + // Version qualified, delete SQL comments + $buf = preg_replace('/^--\sV([0-9\.]+)/i', '', $buf); + //print "Ligne $i qualifiee par version: ".$buf.'
'; + } + } + if ($choix == 2 && preg_match('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', $buf, $reg)) + { + $versioncommande = explode('.', $reg[1]); + //print var_dump($versioncommande); + //print var_dump($versionarray); + if (count($versioncommande) && count($versionarray) && versioncompare($versioncommande, $versionarray) <= 0) + { + // Version qualified, delete SQL comments + $buf = preg_replace('/^--\sPOSTGRESQL\sV([0-9\.]+)/i', '', $buf); + //print "Ligne $i qualifiee par version: ".$buf.'
'; + } + } + + // Ajout ligne si non commentaire + if (!preg_match('/^--/i', $buf)) + $buffer .= $buf; + } + fclose($fp); + + // Si plusieurs requetes, on boucle sur chaque + $listesql = explode(';', $buffer); + foreach ($listesql as $req) + { + $buffer = trim($req); + if ($buffer) + { + // Replace the prefix tables + if ($dolibarr_main_db_prefix != 'llx_') + { + $buffer = preg_replace('/llx_/i', $dolibarr_main_db_prefix, $buffer); + } + + //print "Creation des cles et index de la table $name: '$buffer'"; + $requestnb++; + + $resql = $db->query($buffer, 0, 'dml'); + if ($resql) + { + //print "OK requete ==== $buffer"; + $db->free($resql); + } + else + { + if ($db->errno() == 'DB_ERROR_KEY_NAME_ALREADY_EXISTS' || + $db->errno() == 'DB_ERROR_CANNOT_CREATE' || + $db->errno() == 'DB_ERROR_PRIMARY_KEY_ALREADY_EXISTS' || + $db->errno() == 'DB_ERROR_TABLE_OR_KEY_ALREADY_EXISTS' || + preg_match('/duplicate key name/i', $db->error())) + { + //print "Deja existante"; + $key_exists = 1; + } + else + { + print "".$langs->trans("CreateOtherKeysForTable", $name); + print "
\n".$langs->trans("Request").' '.$requestnb.' : '.$db->lastqueryerror(); + print "\n"; + print ''.$langs->trans("ErrorSQL")." ".$db->errno()." ".$db->error().''; + $error++; + } + } + } + } + } + else + { + print "".$langs->trans("CreateOtherKeysForTable", $name); + print ""; + print ''.$langs->trans("Error")." Failed to open file ".$dir.$file.""; + $error++; + } +} + +if ($tablefound && $error == 0) +{ + print ''; + print $langs->trans("OtherKeysCreation").'Ok'; + $okkeys = 1; +} + \ No newline at end of file