diff --git a/htdocs/admin/delivery.php b/htdocs/admin/delivery.php index c05bd985705..d9c1b2ebe17 100644 --- a/htdocs/admin/delivery.php +++ b/htdocs/admin/delivery.php @@ -54,113 +54,113 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; if ($action == 'updateMask') { - $maskconstdelivery = GETPOST('maskconstdelivery', 'alpha'); - $maskdelivery = GETPOST('maskdelivery', 'alpha'); - if ($maskconstdelivery) $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity); + $maskconstdelivery = GETPOST('maskconstdelivery', 'alpha'); + $maskdelivery = GETPOST('maskdelivery', 'alpha'); + if ($maskconstdelivery) $res = dolibarr_set_const($db, $maskconstdelivery, $maskdelivery, 'chaine', 0, '', $conf->entity); - if (!$res > 0) $error++; + if (!$res > 0) $error++; if (!$error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } else { - setEventMessages($langs->trans("Error"), null, 'errors'); - } + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } } if ($action == 'set_DELIVERY_FREE_TEXT') { - $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string - $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity); + $free = GETPOST('DELIVERY_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string + $res = dolibarr_set_const($db, "DELIVERY_FREE_TEXT", $free, 'chaine', 0, '', $conf->entity); - if (!$res > 0) $error++; + if (!$res > 0) $error++; if (!$error) - { - setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); - } else { - setEventMessages($langs->trans("Error"), null, 'errors'); - } + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } } if ($action == 'specimen') { - $modele = GETPOST('module', 'alpha'); + $modele = GETPOST('module', 'alpha'); - $sending = new Delivery($db); - $sending->initAsSpecimen(); + $sending = new Delivery($db); + $sending->initAsSpecimen(); - // Search template files - $file = ''; $classname = ''; $filefound = 0; - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) - { - $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0); - if (file_exists($file)) - { - $filefound = 1; - $classname = "pdf_".$modele; - break; - } - } + // Search template files + $file = ''; $classname = ''; $filefound = 0; + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) + { + $file = dol_buildpath($reldir."core/modules/delivery/doc/pdf_".$modele.".modules.php", 0); + if (file_exists($file)) + { + $filefound = 1; + $classname = "pdf_".$modele; + break; + } + } - if ($filefound) - { - require_once $file; + if ($filefound) + { + require_once $file; - $module = new $classname($db); + $module = new $classname($db); - if ($module->write_file($sending, $langs) > 0) - { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf"); - return; - } else { - setEventMessages($module->error, $module->errors, 'errors'); - dol_syslog($module->error, LOG_ERR); - } - } else { + if ($module->write_file($sending, $langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=delivery&file=SPECIMEN.pdf"); + return; + } else { + setEventMessages($module->error, $module->errors, 'errors'); + dol_syslog($module->error, LOG_ERR); + } + } else { setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors'); - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); - } + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + } } if ($action == 'set') { - $ret = addDocumentModel($value, $type, $label, $scandir); + $ret = addDocumentModel($value, $type, $label, $scandir); } if ($action == 'del') { - $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - if ($conf->global->DELIVERY_ADDON_PDF == "$value") dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity); - } + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + if ($conf->global->DELIVERY_ADDON_PDF == "$value") dolibarr_del_const($db, 'DELIVERY_ADDON_PDF', $conf->entity); + } } if ($action == 'setdoc') { - if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) - { - // La constante qui a ete lue en avant du nouveau set - // on passe donc par une variable pour avoir un affichage coherent - $conf->global->DELIVERY_ADDON_PDF = $value; - } + if (dolibarr_set_const($db, "DELIVERY_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) + { + // La constante qui a ete lue en avant du nouveau set + // on passe donc par une variable pour avoir un affichage coherent + $conf->global->DELIVERY_ADDON_PDF = $value; + } - // On active le modele - $ret = delDocumentModel($value, $type); - if ($ret > 0) - { - $ret = addDocumentModel($value, $type, $label, $scandir); - } + // On active le modele + $ret = delDocumentModel($value, $type); + if ($ret > 0) + { + $ret = addDocumentModel($value, $type, $label, $scandir); + } } if ($action == 'setmod') { - // TODO Verifier si module numerotation choisi peut etre active - // par appel methode canBeActivated + // TODO Verifier si module numerotation choisi peut etre active + // par appel methode canBeActivated - dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity); + dolibarr_set_const($db, "DELIVERY_ADDON_NUMBER", $value, 'chaine', 0, '', $conf->entity); } @@ -199,79 +199,79 @@ clearstatcache(); foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/delivery/"); + $dir = dol_buildpath($reldir."core/modules/delivery/"); - if (is_dir($dir)) - { - $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) { - $file = substr($file, 0, dol_strlen($file) - 4); + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) + { + if (preg_match('/^mod_delivery_([a-z0-9_]*)\.php$/', $file)) { + $file = substr($file, 0, dol_strlen($file) - 4); - require_once $dir.$file.'.php'; + require_once $dir.$file.'.php'; - $module = new $file; + $module = new $file; if ($module->isEnabled()) - { + { // Show modules according to features level if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue; if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue; - print ''.$module->name."\n"; - print $module->info(); - print ''; + print ''.$module->name."\n"; + print $module->info(); + print ''; - // Show example of numbering module - print ''; - $tmp = $module->getExample(); - if (preg_match('/^Error/', $tmp)) { + // Show example of numbering module + print ''; + $tmp = $module->getExample(); + if (preg_match('/^Error/', $tmp)) { $langs->load("errors"); print '
'.$langs->trans($tmp).'
'; } elseif ($tmp == 'NotConfigured') print $langs->trans($tmp); - else print $tmp; - print ''."\n"; + else print $tmp; + print ''."\n"; - print ''; - if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") - { - print img_picto($langs->trans("Activated"), 'switch_on'); - } else { - print ''.img_picto($langs->trans("Disabled"), 'switch_off').''; - } - print ''; + print ''; + if ($conf->global->DELIVERY_ADDON_NUMBER == "$file") + { + print img_picto($langs->trans("Activated"), 'switch_on'); + } else { + print ''.img_picto($langs->trans("Disabled"), 'switch_off').''; + } + print ''; - $delivery = new Delivery($db); - $delivery->initAsSpecimen(); + $delivery = new Delivery($db); + $delivery->initAsSpecimen(); - // Info - $htmltooltip = ''; - $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; - $nextval = $module->getNextValue($mysoc, $delivery); - if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval - $htmltooltip .= ''.$langs->trans("NextValue").': '; - if ($nextval) { - if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') - $nextval = $langs->trans($nextval); - $htmltooltip .= $nextval.'
'; - } else { - $htmltooltip .= $langs->trans($module->error).'
'; - } - } + // Info + $htmltooltip = ''; + $htmltooltip .= ''.$langs->trans("Version").': '.$module->getVersion().'
'; + $nextval = $module->getNextValue($mysoc, $delivery); + if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval + $htmltooltip .= ''.$langs->trans("NextValue").': '; + if ($nextval) { + if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') + $nextval = $langs->trans($nextval); + $htmltooltip .= $nextval.'
'; + } else { + $htmltooltip .= $langs->trans($module->error).'
'; + } + } - print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print ''; + print ''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print ''; - print ''; - } - } - } - closedir($handle); - } - } + print ''; + } + } + } + closedir($handle); + } + } } print ''; @@ -321,14 +321,14 @@ clearstatcache(); foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/delivery/doc/"); + $dir = dol_buildpath($reldir."core/modules/delivery/doc/"); - if (is_dir($dir)) - { - $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) + if (is_dir($dir)) + { + $handle = opendir($dir); + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) { $filelist[] = $file; } @@ -337,79 +337,79 @@ foreach ($dirmodels as $reldir) foreach ($filelist as $file) { - if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) - { - if (file_exists($dir.'/'.$file)) - { - $name = substr($file, 4, dol_strlen($file) - 16); - $classname = substr($file, 0, dol_strlen($file) - 12); + if (preg_match('/\.modules\.php$/i', $file) && preg_match('/^(pdf_|doc_)/', $file)) + { + if (file_exists($dir.'/'.$file)) + { + $name = substr($file, 4, dol_strlen($file) - 16); + $classname = substr($file, 0, dol_strlen($file) - 12); - require_once $dir.'/'.$file; - $module = new $classname($db); + require_once $dir.'/'.$file; + $module = new $classname($db); - $modulequalified = 1; - if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; - if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; + $modulequalified = 1; + if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) $modulequalified = 0; + if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) $modulequalified = 0; - if ($modulequalified) - { - print ''; - print (empty($module->name) ? $name : $module->name); - print "\n"; - if (method_exists($module, 'info')) print $module->info($langs); - else print $module->description; - print ''; + if ($modulequalified) + { + print ''; + print (empty($module->name) ? $name : $module->name); + print "\n"; + if (method_exists($module, 'info')) print $module->info($langs); + else print $module->description; + print ''; - // Active - if (in_array($name, $def)) - { - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'; - print img_picto($langs->trans("Enabled"), 'switch_on'); - print ''; - print ""; - } else { - print "\n"; - print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').''; - print ""; - } + // Active + if (in_array($name, $def)) + { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'; + print img_picto($langs->trans("Enabled"), 'switch_on'); + print ''; + print ""; + } else { + print "\n"; + print 'scandir.'&label='.urlencode($module->name).'">'.img_picto($langs->trans("Disabled"), 'switch_off').''; + print ""; + } - // Default - print ""; - if ($conf->global->DELIVERY_ADDON_PDF == "$name") - { - print img_picto($langs->trans("Default"), 'on'); - } else { - print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; - } - print ''; + // Default + print ""; + if ($conf->global->DELIVERY_ADDON_PDF == "$name") + { + print img_picto($langs->trans("Default"), 'on'); + } else { + print 'scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').''; + } + print ''; - // Info - $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); - $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; - $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; - $htmltooltip .= '
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); - print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); - print ''; + // Info + $htmltooltip = ''.$langs->trans("Type").': '.($module->type ? $module->type : $langs->trans("Unknown")); + $htmltooltip .= '
'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur; + $htmltooltip .= '

'.$langs->trans("FeaturesSupported").':'; + $htmltooltip .= '
'.$langs->trans("Logo").': '.yn($module->option_logo, 1, 1); + print ''; + print $form->textwithpicto('', $htmltooltip, 1, 0); + print ''; - // Preview - print ''; - if ($module->type == 'pdf') - { - print ''.img_object($langs->trans("Preview"), 'sending').''; - } else { - print img_object($langs->trans("PreviewNotAvailable"), 'generic'); - } - print ''; + // Preview + print ''; + if ($module->type == 'pdf') + { + print ''.img_object($langs->trans("Preview"), 'sending').''; + } else { + print img_object($langs->trans("PreviewNotAvailable"), 'generic'); + } + print ''; - print ''; - } - } - } - } - } - } + print ''; + } + } + } + } + } + } } print ''; @@ -440,11 +440,11 @@ print $form->textwithpicto($langs->trans("FreeLegalTextOnDeliveryReceipts"), $la $variablename = 'DELIVERY_FREE_TEXT'; if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) { - print ''; + print ''; } else { - include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes'); - print $doleditor->Create(); + include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor($variablename, $conf->global->$variablename, '', 80, 'dolibarr_notes'); + print $doleditor->Create(); } print ''; print ''; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 7496f98a394..2e02323c090 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -124,9 +124,9 @@ class Propal extends CommonObject */ public $datec; - /** - * @var integer|string $date_creation; - */ + /** + * @var integer|string $date_creation; + */ public $date_creation; /** @@ -136,13 +136,13 @@ class Propal extends CommonObject public $datev; /** - * @var integer|string $date_validation; - */ + * @var integer|string $date_validation; + */ public $date_validation; /** - * @var integer|string date of the quote; - */ + * @var integer|string date of the quote; + */ public $date; /** @@ -186,9 +186,9 @@ class Propal extends CommonObject public $remise_absolue = 0; /** - * @var int ID - * @deprecated - */ + * @var int ID + * @deprecated + */ public $fk_address; public $address_type; @@ -218,8 +218,8 @@ class Propal extends CommonObject // Multicurrency /** - * @var int ID - */ + * @var int ID + */ public $fk_multicurrency; public $multicurrency_code; @@ -342,7 +342,7 @@ class Propal extends CommonObject * @param int $socid Id third party * @param int $propalid Id proposal */ - public function __construct($db, $socid = 0, $propalid = 0) + public function __construct($db, $socid = 0, $propalid = 0) { global $conf, $langs; @@ -357,7 +357,7 @@ class Propal extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add line into array products * $this->thirdparty should be loaded @@ -370,9 +370,9 @@ class Propal extends CommonObject * TODO Replace calls to this function by generation objet Ligne * inserted into table $this->products */ - public function add_product($idproduct, $qty, $remise_percent = 0) + public function add_product($idproduct, $qty, $remise_percent = 0) { - // phpcs:enable + // phpcs:enable global $conf, $mysoc; if (!$qty) $qty = 1; @@ -417,16 +417,16 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Adding line of fixed discount in the proposal in DB * * @param int $idremise Id of fixed discount * @return int >0 if OK, <0 if KO */ - public function insert_discount($idremise) + public function insert_discount($idremise) { - // phpcs:enable + // phpcs:enable global $langs; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -493,43 +493,43 @@ class Propal extends CommonObject } } - /** - * Add a proposal line into database (linked to product/service or not) - * The parameters are already supposed to be appropriate and with final values to the call - * of this method. Also, for the VAT rate, it must have already been defined - * by whose calling the method get_default_tva (societe_vendeuse, societe_acheteuse, '' product) - * and desc must already have the right value (it's up to the caller to manage multilanguage) - * - * @param string $desc Description of line - * @param float $pu_ht Unit price - * @param float $qty Quantity - * @param float $txtva Force Vat rate, -1 for auto (Can contain the vat_src_code too with syntax '9.9 (CODE)') - * @param float $txlocaltax1 Local tax 1 rate (deprecated, use instead txtva with code inside) - * @param float $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) - * @param int $fk_product Product/Service ID predefined - * @param float $remise_percent Pourcentage de remise de la ligne - * @param string $price_base_type HT or TTC - * @param float $pu_ttc Prix unitaire TTC - * @param int $info_bits Bits for type of lines - * @param int $type Type of line (0=product, 1=service). Not used if fk_product is defined, the type of product is used. - * @param int $rang Position of line - * @param int $special_code Special code (also used by externals modules!) - * @param int $fk_parent_line Id of parent line - * @param int $fk_fournprice Id supplier price - * @param int $pa_ht Buying price without tax - * @param string $label ??? - * @param int $date_start Start date of the line - * @param int $date_end End date of the line - * @param array $array_options extrafields array - * @param string $fk_unit Code of the unit to use. Null to use the default one - * @param string $origin Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be 'orderdet', 'propaldet'..., else 'order','propal,'.... - * @param int $origin_id Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be Id of origin object (aka line id), else object id - * @param double $pu_ht_devise Unit price in currency - * @param int $fk_remise_except Id discount if line is from a discount - * @return int >0 if OK, <0 if KO - * @see add_product() - */ - public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0) + /** + * Add a proposal line into database (linked to product/service or not) + * The parameters are already supposed to be appropriate and with final values to the call + * of this method. Also, for the VAT rate, it must have already been defined + * by whose calling the method get_default_tva (societe_vendeuse, societe_acheteuse, '' product) + * and desc must already have the right value (it's up to the caller to manage multilanguage) + * + * @param string $desc Description of line + * @param float $pu_ht Unit price + * @param float $qty Quantity + * @param float $txtva Force Vat rate, -1 for auto (Can contain the vat_src_code too with syntax '9.9 (CODE)') + * @param float $txlocaltax1 Local tax 1 rate (deprecated, use instead txtva with code inside) + * @param float $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) + * @param int $fk_product Product/Service ID predefined + * @param float $remise_percent Pourcentage de remise de la ligne + * @param string $price_base_type HT or TTC + * @param float $pu_ttc Prix unitaire TTC + * @param int $info_bits Bits for type of lines + * @param int $type Type of line (0=product, 1=service). Not used if fk_product is defined, the type of product is used. + * @param int $rang Position of line + * @param int $special_code Special code (also used by externals modules!) + * @param int $fk_parent_line Id of parent line + * @param int $fk_fournprice Id supplier price + * @param int $pa_ht Buying price without tax + * @param string $label ??? + * @param int $date_start Start date of the line + * @param int $date_end End date of the line + * @param array $array_options extrafields array + * @param string $fk_unit Code of the unit to use. Null to use the default one + * @param string $origin Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be 'orderdet', 'propaldet'..., else 'order','propal,'.... + * @param int $origin_id Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be Id of origin object (aka line id), else object id + * @param double $pu_ht_devise Unit price in currency + * @param int $fk_remise_except Id discount if line is from a discount + * @return int >0 if OK, <0 if KO + * @see add_product() + */ + public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0) { global $mysoc, $conf, $langs; @@ -706,27 +706,27 @@ class Propal extends CommonObject // Reorder if child line if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); - // Mise a jour informations denormalisees au niveau de la propale meme - $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. - if ($result > 0) - { - $this->db->commit(); - return $this->line->id; - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } else { - $this->error = $this->line->error; - $this->db->rollback(); - return -2; - } - } else { + // Mise a jour informations denormalisees au niveau de la propale meme + $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + if ($result > 0) + { + $this->db->commit(); + return $this->line->id; + } else { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } else { + $this->error = $this->line->error; + $this->db->rollback(); + return -2; + } + } else { dol_syslog(get_class($this)."::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR); return -3; } - } + } /** @@ -757,11 +757,11 @@ class Propal extends CommonObject * @param int $notrigger disable line update trigger * @return int 0 if OK, <0 if KO */ - public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0) + public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0) { global $mysoc, $langs; - dol_syslog(get_class($this)."::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent, + dol_syslog(get_class($this)."::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, desc=$desc, price_base_type=$price_base_type, info_bits=$info_bits, special_code=$special_code, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, type=$type, date_start=$date_start, date_end=$date_end"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -778,11 +778,11 @@ class Propal extends CommonObject if (!empty($qty) && $special_code == 3) $special_code = 0; // Remove option tag if (empty($type)) $type = 0; - if ($date_start && $date_end && $date_start > $date_end) { - $langs->load("errors"); - $this->error = $langs->trans('ErrorStartDateGreaterEnd'); - return -1; - } + if ($date_start && $date_end && $date_start > $date_end) { + $langs->load("errors"); + $this->error = $langs->trans('ErrorStartDateGreaterEnd'); + return -1; + } if ($this->statut == self::STATUS_DRAFT) { @@ -926,7 +926,7 @@ class Propal extends CommonObject * @param int $lineid Id of line to delete * @return int >0 if OK, <0 if KO */ - public function deleteline($lineid) + public function deleteline($lineid) { global $user; @@ -964,7 +964,7 @@ class Propal extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >=0 if OK */ - public function create($user, $notrigger = 0) + public function create($user, $notrigger = 0) { global $conf, $hookmanager; $error = 0; @@ -1102,62 +1102,62 @@ class Propal extends CommonObject $resql = $this->db->query($sql); if (!$resql) $error++; - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects - { - $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds - } + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } - // Add object linked - if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) - { - foreach ($this->linked_objects as $origin => $tmp_origin_id) - { - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) - { - foreach ($tmp_origin_id as $origin_id) - { - $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { - $this->error = $this->db->lasterror(); - $error++; - } - } - } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) - { - $origin_id = $tmp_origin_id; - $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { - $this->error = $this->db->lasterror(); - $error++; - } - } - } - } + // Add object linked + if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) + { + foreach ($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach ($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (!$ret) + { + $this->error = $this->db->lasterror(); + $error++; + } + } + } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (!$ret) + { + $this->error = $this->db->lasterror(); + $error++; + } + } + } + } - /* + /* * Insertion du detail des produits dans la base * Insert products detail in database */ - if (!$error) - { - $fk_parent_line = 0; - $num = count($this->lines); + if (!$error) + { + $fk_parent_line = 0; + $num = count($this->lines); for ($i = 0; $i < $num; $i++) { - if (!is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API - { // Convert into object this->lines[$i]. - $line = (object) $this->lines[$i]; - } else { - $line = $this->lines[$i]; - } + if (!is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API + { // Convert into object this->lines[$i]. + $line = (object) $this->lines[$i]; + } else { + $line = $this->lines[$i]; + } // Reset fk_parent_line for line that are not child lines or special product if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { $fk_parent_line = 0; } - // Complete vat rate with code + // Complete vat rate with code $vatrate = $line->tva_tx; if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')'; @@ -1273,7 +1273,7 @@ class Propal extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Insert into DB a proposal object completely defined by its data members (ex, results from copy). * @@ -1281,9 +1281,9 @@ class Propal extends CommonObject * @return int Id of the new object if ok, <0 if ko * @see create() */ - public function create_from($user) + public function create_from($user) { - // phpcs:enable + // phpcs:enable // i love this function because $this->products is not used in create function... $this->products = $this->lines; @@ -1324,10 +1324,10 @@ class Propal extends CommonObject { if ($objsoc->fetch($socid) > 0) { - $object->socid = $objsoc->id; - $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); - $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $object->fk_delivery_address = ''; + $object->socid = $objsoc->id; + $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $object->fk_delivery_address = ''; /*if (!empty($conf->projet->enabled)) { @@ -1339,7 +1339,7 @@ class Propal extends CommonObject $clonedObj->fk_project = ''; } }*/ - $object->fk_project = ''; // A cloned proposal is set by default to no project. + $object->fk_project = ''; // A cloned proposal is set by default to no project. } // reset ref_client @@ -1347,7 +1347,7 @@ class Propal extends CommonObject // TODO Change product price if multi-prices } else { - $objsoc->fetch($object->socid); + $objsoc->fetch($object->socid); } $object->id = 0; @@ -1372,18 +1372,18 @@ class Propal extends CommonObject $result = $object->create($user); if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); - $error++; + $this->error = $object->error; + $this->errors = array_merge($this->errors, $object->errors); + $error++; } if (!$error) { // copy internal contacts - if ($object->copy_linked_contact($this, 'internal') < 0) - { + if ($object->copy_linked_contact($this, 'internal') < 0) + { $error++; - } + } } if (!$error) @@ -1391,7 +1391,7 @@ class Propal extends CommonObject // copy external contacts if same company if ($this->socid == $object->socid) { - if ($object->copy_linked_contact($this, 'external') < 0) + if ($object->copy_linked_contact($this, 'external') < 0) $error++; } } @@ -1429,7 +1429,7 @@ class Propal extends CommonObject * @param string $ref_ext Ref ext of proposal * @return int >0 if OK, <0 if KO */ - public function fetch($rowid, $ref = '', $ref_ext = '') + public function fetch($rowid, $ref = '', $ref_ext = '') { $sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; @@ -1595,7 +1595,7 @@ class Propal extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - public function update(User $user, $notrigger = 0) + public function update(User $user, $notrigger = 0) { global $conf; @@ -1684,7 +1684,7 @@ class Propal extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load array lines * @@ -1696,7 +1696,7 @@ class Propal extends CommonObject public function fetch_lines($only_product = 0, $loadalsotranslation = 0) { global $langs, $conf; - // phpcs:enable + // phpcs:enable $this->lines = array(); $sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,'; @@ -1790,11 +1790,11 @@ class Propal extends CommonObject $line->fetch_optionals(); // multilangs - if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) { - $line = new Product($this->db); - $line->fetch($objp->fk_product); - $line->getMultiLangs(); - } + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) { + $line = new Product($this->db); + $line->fetch($objp->fk_product); + $line->getMultiLangs(); + } $this->lines[$i] = $line; //dol_syslog("1 ".$line->fk_product); @@ -1818,7 +1818,7 @@ class Propal extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0=execute triggers * @return int <0 if KO, 0=Nothing done, >=0 if OK */ - public function valid($user, $notrigger = 0) + public function valid($user, $notrigger = 0) { global $conf; @@ -1933,7 +1933,7 @@ class Propal extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define proposal date * @@ -1942,9 +1942,9 @@ class Propal extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_date($user, $date, $notrigger = 0) + public function set_date($user, $date, $notrigger = 0) { - // phpcs:enable + // phpcs:enable if (empty($date)) { $this->error = 'ErrorBadParameter'; @@ -2000,7 +2000,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define end validity date * @@ -2009,9 +2009,9 @@ class Propal extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_echeance($user, $date_fin_validite, $notrigger = 0) + public function set_echeance($user, $date_fin_validite, $notrigger = 0) { - // phpcs:enable + // phpcs:enable if (!empty($user->rights->propal->creer)) { $error = 0; @@ -2134,7 +2134,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set delivery * @@ -2201,7 +2201,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set source of demand * @@ -2270,7 +2270,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set customer reference number * @@ -2331,7 +2331,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set an overall discount on the proposal * @@ -2396,7 +2396,7 @@ class Propal extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set an absolute overall discount on the proposal * @@ -2676,7 +2676,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status * @@ -2825,7 +2825,7 @@ class Propal extends CommonObject return $this->InvoiceArrayList($this->id); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Returns an array with id and ref of related invoices * @@ -3091,7 +3091,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Change source demand * @@ -3446,7 +3446,7 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Charge indicateurs this->nb de tableau de bord * @@ -4260,7 +4260,7 @@ class PropaleLigne extends CommonObjectLine } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update DB line fields total_xxx * Used by migration diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index eb93a125fb5..901a0f6f385 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -242,7 +242,7 @@ if (empty($reshook)) { $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); - $selectedLines = GETPOST('toselect', 'array'); + $selectedLines = GETPOST('toselect', 'array'); if ($datecommande == '') { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors'); @@ -349,7 +349,7 @@ if (empty($reshook)) for ($i = 0; $i < $num; $i++) { - if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines + if (!in_array($lines[$i]->id, $selectedLines)) continue; // Skip unselected lines $label = (!empty($lines[$i]->label) ? $lines[$i]->label : ''); $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : ''); @@ -738,8 +738,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 price per customer @@ -1284,82 +1284,82 @@ if (empty($reshook)) // add lines from objectlinked if ($action == 'import_lines_from_object' - && $usercancreate - && $object->statut == Commande::STATUS_DRAFT + && $usercancreate + && $object->statut == Commande::STATUS_DRAFT ) { - $fromElement = GETPOST('fromelement'); - $fromElementid = GETPOST('fromelementid'); - $importLines = GETPOST('line_checkbox'); + $fromElement = GETPOST('fromelement'); + $fromElementid = GETPOST('fromelementid'); + $importLines = GETPOST('line_checkbox'); - if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) - { - if ($fromElement == 'commande') - { - dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'OrderLine'; - } elseif ($fromElement == 'propal') - { - dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); - $lineClassName = 'PropaleLigne'; - } - $nextRang = count($object->lines) + 1; - $importCount = 0; - $error = 0; - foreach ($importLines as $lineId) - { - $lineId = intval($lineId); - $originLine = new $lineClassName($db); - if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) - { - $originLine->fetch_optionals(); - $desc = $originLine->desc; - $pu_ht = $originLine->subprice; - $qty = $originLine->qty; - $txtva = $originLine->tva_tx; - $txlocaltax1 = $originLine->localtax1_tx; - $txlocaltax2 = $originLine->localtax2_tx; - $fk_product = $originLine->fk_product; - $remise_percent = $originLine->remise_percent; - $date_start = $originLine->date_start; - $date_end = $originLine->date_end; - $ventil = 0; - $info_bits = $originLine->info_bits; - $fk_remise_except = $originLine->fk_remise_except; - $price_base_type = 'HT'; - $pu_ttc = 0; - $type = $originLine->product_type; - $rang = $nextRang++; - $special_code = $originLine->special_code; - $origin = $originLine->element; - $origin_id = $originLine->id; - $fk_parent_line = 0; - $fk_fournprice = $originLine->fk_fournprice; - $pa_ht = $originLine->pa_ht; - $label = $originLine->label; - $array_options = $originLine->array_options; - $situation_percent = 100; - $fk_prev_id = ''; - $fk_unit = $originLine->fk_unit; - $pu_ht_devise = $originLine->multicurrency_subprice; + if (!empty($importLines) && is_array($importLines) && !empty($fromElement) && ctype_alpha($fromElement) && !empty($fromElementid)) + { + if ($fromElement == 'commande') + { + dol_include_once('/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'OrderLine'; + } elseif ($fromElement == 'propal') + { + dol_include_once('/comm/'.$fromElement.'/class/'.$fromElement.'.class.php'); + $lineClassName = 'PropaleLigne'; + } + $nextRang = count($object->lines) + 1; + $importCount = 0; + $error = 0; + foreach ($importLines as $lineId) + { + $lineId = intval($lineId); + $originLine = new $lineClassName($db); + if (intval($fromElementid) > 0 && $originLine->fetch($lineId) > 0) + { + $originLine->fetch_optionals(); + $desc = $originLine->desc; + $pu_ht = $originLine->subprice; + $qty = $originLine->qty; + $txtva = $originLine->tva_tx; + $txlocaltax1 = $originLine->localtax1_tx; + $txlocaltax2 = $originLine->localtax2_tx; + $fk_product = $originLine->fk_product; + $remise_percent = $originLine->remise_percent; + $date_start = $originLine->date_start; + $date_end = $originLine->date_end; + $ventil = 0; + $info_bits = $originLine->info_bits; + $fk_remise_except = $originLine->fk_remise_except; + $price_base_type = 'HT'; + $pu_ttc = 0; + $type = $originLine->product_type; + $rang = $nextRang++; + $special_code = $originLine->special_code; + $origin = $originLine->element; + $origin_id = $originLine->id; + $fk_parent_line = 0; + $fk_fournprice = $originLine->fk_fournprice; + $pa_ht = $originLine->pa_ht; + $label = $originLine->label; + $array_options = $originLine->array_options; + $situation_percent = 100; + $fk_prev_id = ''; + $fk_unit = $originLine->fk_unit; + $pu_ht_devise = $originLine->multicurrency_subprice; - $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $date_start, $date_end, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise); + $res = $object->addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc, $date_start, $date_end, $type, $rang, $special_code, $fk_parent_line, $fk_fournprice, $pa_ht, $label, $array_options, $fk_unit, $origin, $origin_id, $pu_ht_devise); - if ($res > 0) { - $importCount++; - } else { - $error++; - } - } else { - $error++; - } - } + if ($res > 0) { + $importCount++; + } else { + $error++; + } + } else { + $error++; + } + } - if ($error) - { - setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); - } - } + if ($error) + { + setEventMessages($langs->trans('ErrorsOnXLines', $error), null, 'errors'); + } + } } // Actions when printing a doc from card @@ -1849,7 +1849,7 @@ if ($action == 'create' && $usercancreate) print ''; } - print ''; + print ''; } else { // Mode view $now = dol_now(); @@ -2635,9 +2635,9 @@ if ($action == 'create' && $usercancreate) $compatibleImportElementsList = false; if ($usercancreate - && $object->statut == Commande::STATUS_DRAFT) + && $object->statut == Commande::STATUS_DRAFT) { - $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements + $compatibleImportElementsList = array('commande', 'propal'); // import from linked elements } $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); diff --git a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php index bc86591fc22..1d367774432 100644 --- a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php +++ b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php @@ -31,166 +31,166 @@ include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; class box_supplier_orders_awaiting_reception extends ModeleBoxes { - public $boxcode = "supplierordersawaitingreception"; - public $boximg = "object_order"; - public $boxlabel = "BoxLatestSupplierOrdersAwaitingReception"; - public $depends = array("fournisseur"); + public $boxcode = "supplierordersawaitingreception"; + public $boximg = "object_order"; + public $boxlabel = "BoxLatestSupplierOrdersAwaitingReception"; + public $depends = array("fournisseur"); - /** - * @var DoliDB Database handler. - */ - public $db; + /** + * @var DoliDB Database handler. + */ + public $db; - public $param; - public $info_box_head = array(); - public $info_box_contents = array(); + public $param; + public $info_box_head = array(); + public $info_box_contents = array(); - /** - * Constructor - * - * @param DoliDB $db Database handler - * @param string $param More parameters - */ - public function __construct($db, $param) - { - global $user; + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param) + { + global $user; - $this->db = $db; + $this->db = $db; - $this->hidden = !($user->rights->fournisseur->commande->lire); - } + $this->hidden = !($user->rights->fournisseur->commande->lire); + } - /** - * Load data into info_box_contents array to show array later. - * - * @param int $max Maximum number of records to load - * @return void - */ - public function loadBox($max = 5) - { - global $conf, $user, $langs; - $langs->loadLangs(array("boxes", "sendings", "orders")); + /** + * Load data into info_box_contents array to show array later. + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $conf, $user, $langs; + $langs->loadLangs(array("boxes", "sendings", "orders")); - $this->max = $max; + $this->max = $max; - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; - $supplierorderstatic = new CommandeFournisseur($this->db); - include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; - $thirdpartytmp = new Fournisseur($this->db); + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; + $supplierorderstatic = new CommandeFournisseur($this->db); + include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; + $thirdpartytmp = new Fournisseur($this->db); - $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max)); + $this->info_box_head = array('text' => $langs->trans("BoxTitleSupplierOrdersAwaitingReception", $max)); - if ($user->rights->fournisseur->commande->lire) - { - $sql = "SELECT s.nom as name, s.rowid as socid,"; - $sql .= " s.code_client, s.code_fournisseur, s.email,"; - $sql .= " s.logo,"; - $sql .= " c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison, "; - $sql .= " c.total_ht,"; - $sql .= " c.tva as total_tva,"; - $sql .= " c.total_ttc,"; - $sql .= " c.fk_statut"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE c.fk_soc = s.rowid"; - $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; - $sql .= " AND c.fk_statut = ".CommandeFournisseur::STATUS_ORDERSENT; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($user->socid) $sql .= " AND s.rowid = ".$user->socid; - if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY c.date_commande DESC, c.ref DESC "; - else $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC "; - $sql .= $this->db->plimit($max, 0); + if ($user->rights->fournisseur->commande->lire) + { + $sql = "SELECT s.nom as name, s.rowid as socid,"; + $sql .= " s.code_client, s.code_fournisseur, s.email,"; + $sql .= " s.logo,"; + $sql .= " c.rowid, c.ref, c.tms, c.date_commande, c.date_livraison, "; + $sql .= " c.total_ht,"; + $sql .= " c.tva as total_tva,"; + $sql .= " c.total_ttc,"; + $sql .= " c.fk_statut"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; + if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE c.fk_soc = s.rowid"; + $sql .= " AND c.entity IN (".getEntity('supplier_order').")"; + $sql .= " AND c.fk_statut = ".CommandeFournisseur::STATUS_ORDERSENT; + if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($user->socid) $sql .= " AND s.rowid = ".$user->socid; + if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY c.date_commande DESC, c.ref DESC "; + else $sql .= " ORDER BY c.date_livraison ASC, c.fk_statut ASC "; + $sql .= $this->db->plimit($max, 0); - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); - $line = 0; - while ($line < $num) { - $objp = $this->db->fetch_object($result); - $date = $this->db->jdate($objp->date_commande); - $delivery_date = $this->db->jdate($objp->date_livraison); + $line = 0; + while ($line < $num) { + $objp = $this->db->fetch_object($result); + $date = $this->db->jdate($objp->date_commande); + $delivery_date = $this->db->jdate($objp->date_livraison); $datem = $this->db->jdate($objp->tms); - $supplierorderstatic->date_livraison = $delivery_date; - $supplierorderstatic->statut = $objp->fk_statut; + $supplierorderstatic->date_livraison = $delivery_date; + $supplierorderstatic->statut = $objp->fk_statut; $supplierorderstatic->id = $objp->rowid; $supplierorderstatic->ref = $objp->ref; $thirdpartytmp->id = $objp->socid; - $thirdpartytmp->name = $objp->name; - $thirdpartytmp->email = $objp->email; - $thirdpartytmp->fournisseur = 1; - $thirdpartytmp->code_fournisseur = $objp->code_fournisseur; - $thirdpartytmp->logo = $objp->logo; + $thirdpartytmp->name = $objp->name; + $thirdpartytmp->email = $objp->email; + $thirdpartytmp->fournisseur = 1; + $thirdpartytmp->code_fournisseur = $objp->code_fournisseur; + $thirdpartytmp->logo = $objp->logo; - $this->info_box_contents[$line][] = array( - 'td' => 'class="nowraponall"', - 'text' => $supplierorderstatic->getNomUrl(1), - 'asis' => 1 - ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="nowraponall"', + 'text' => $supplierorderstatic->getNomUrl(1), + 'asis' => 1 + ); - $this->info_box_contents[$line][] = array( - 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', - 'text' => $thirdpartytmp->getNomUrl(1, 'supplier'), - 'asis' => 1, - ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', + 'text' => $thirdpartytmp->getNomUrl(1, 'supplier'), + 'asis' => 1, + ); - $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', - 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), - ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right nowraponall"', + 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), + ); - $delayIcon = ''; - if ($supplierorderstatic->hasDelay()) { - $delayIcon = img_warning($langs->trans("Late")); - } + $delayIcon = ''; + if ($supplierorderstatic->hasDelay()) { + $delayIcon = img_warning($langs->trans("Late")); + } - $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => $delayIcon.' '.dol_print_date($delivery_date, 'day').'', - 'asis' => 1 - ); + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => $delayIcon.' '.dol_print_date($delivery_date, 'day').'', + 'asis' => 1 + ); - $line++; - } + $line++; + } - if ($num == 0) - $this->info_box_contents[$line][] = array( - 'td' => 'class="center"', - 'text' => $langs->trans("NoSupplierOrder"), - ); + if ($num == 0) + $this->info_box_contents[$line][] = array( + 'td' => 'class="center"', + 'text' => $langs->trans("NoSupplierOrder"), + ); - $this->db->free($result); - } else { - $this->info_box_contents[0][] = array( - 'td' => '', - 'maxlength'=>500, - 'text' => ($this->db->error().' sql='.$sql), - ); - } - } else { - $this->info_box_contents[0][] = array( - 'td' => 'class="nohover opacitymedium left"', - 'text' => $langs->trans("ReadPermissionNotAllowed") - ); - } - } + $this->db->free($result); + } else { + $this->info_box_contents[0][] = array( + 'td' => '', + 'maxlength'=>500, + 'text' => ($this->db->error().' sql='.$sql), + ); + } + } else { + $this->info_box_contents[0][] = array( + 'td' => 'class="nohover opacitymedium left"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); + } + } - /** - * Method to show box - * - * @param array $head Array with properties of box title - * @param array $contents Array with properties of box lines - * @param int $nooutput No print, only return string - * @return string - */ - public function showBox($head = null, $contents = null, $nooutput = 0) - { - return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); - } + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 58b36ac3643..04b7d4985cd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -296,11 +296,11 @@ abstract class CommonObject */ public $cond_reglement_id; - /** - * @var int Transport mode ID (For module intracomm report) - * @see setTransportMode() - */ - public $transport_mode_id; + /** + * @var int Transport mode ID (For module intracomm report) + * @see setTransportMode() + */ + public $transport_mode_id; /** * @var int Payment terms ID @@ -2196,42 +2196,42 @@ abstract class CommonObject } } - /** - * Change the transport mode methods - * - * @param int $id Id of new payment method - * @return int >0 if OK, <0 if KO - */ - public function setTransportMode($id) - { - dol_syslog(get_class($this).'::setTransportMode('.$id.')'); - if ($this->statut >= 0 || $this->element == 'societe') - { - $fieldname = 'fk_transport_mode'; - if ($this->element == 'societe') $fieldname = 'transport_mode'; - if (get_class($this) == 'Fournisseur') $fieldname = 'transport_mode_supplier'; + /** + * Change the transport mode methods + * + * @param int $id Id of new payment method + * @return int >0 if OK, <0 if KO + */ + public function setTransportMode($id) + { + dol_syslog(get_class($this).'::setTransportMode('.$id.')'); + if ($this->statut >= 0 || $this->element == 'societe') + { + $fieldname = 'fk_transport_mode'; + if ($this->element == 'societe') $fieldname = 'transport_mode'; + if (get_class($this) == 'Fournisseur') $fieldname = 'transport_mode_supplier'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname.' = '.(($id > 0 || $id == '0') ? $id : 'NULL'); - $sql .= ' WHERE rowid='.$this->id; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET '.$fieldname.' = '.(($id > 0 || $id == '0') ? $id : 'NULL'); + $sql .= ' WHERE rowid='.$this->id; - if ($this->db->query($sql)) - { - $this->transport_mode_id = $id; - // for supplier - if (get_class($this) == 'Fournisseur') $this->transport_mode_supplier_id = $id; - return 1; - } else { - dol_syslog(get_class($this).'::setTransportMode Error '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; - } - } else { - dol_syslog(get_class($this).'::setTransportMode, status of the object is incompatible'); - $this->error='Status of the object is incompatible '.$this->statut; - return -2; - } - } + if ($this->db->query($sql)) + { + $this->transport_mode_id = $id; + // for supplier + if (get_class($this) == 'Fournisseur') $this->transport_mode_supplier_id = $id; + return 1; + } else { + dol_syslog(get_class($this).'::setTransportMode Error '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } else { + dol_syslog(get_class($this).'::setTransportMode, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } /** * Change the retained warranty payments terms @@ -2785,8 +2785,8 @@ abstract class CommonObject */ public function line_max($fk_parent_line = 0) { - // phpcs:enable - $positionfield = 'rang'; + // phpcs:enable + $positionfield = 'rang'; if ($this->table_element == 'bom_bom') $positionfield = 'position'; // Search the last rang with fk_parent_line diff --git a/htdocs/core/lib/propal.lib.php b/htdocs/core/lib/propal.lib.php index ef41614116f..bd3a30151da 100644 --- a/htdocs/core/lib/propal.lib.php +++ b/htdocs/core/lib/propal.lib.php @@ -43,7 +43,7 @@ function propal_prepare_head($object) $h++; if ((empty($conf->commande->enabled) && ((!empty($conf->expedition->enabled) && !empty($conf->expedition_bon->enabled) && $user->rights->expedition->lire) - || (!empty($conf->expedition->enabled) && !empty($conf->delivery_note->enabled) && $user->rights->expedition->delivery->lire)))) + || (!empty($conf->expedition->enabled) && !empty($conf->delivery_note->enabled) && $user->rights->expedition->delivery->lire)))) { $langs->load("sendings"); $text = ''; @@ -57,7 +57,7 @@ function propal_prepare_head($object) if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { - $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); + $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); $head[$h][0] = DOL_URL_ROOT.'/comm/propal/contact.php?id='.$object->id; $head[$h][1] = $langs->trans('ContactsAddresses'); if ($nbContact > 0) $head[$h][1] .= ''.$nbContact.''; @@ -65,29 +65,29 @@ function propal_prepare_head($object) $h++; } - // Show more tabs from modules - // Entries must be declared in modules descriptor with line - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab - // $this->tabs = array('entity:-tabname); to remove a tab - complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal'); + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal'); - if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { - $nbNote = 0; - if (!empty($object->note_private)) $nbNote++; + if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $nbNote = 0; + if (!empty($object->note_private)) $nbNote++; if (!empty($object->note_public)) $nbNote++; - $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id; + $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id; $head[$h][1] = $langs->trans('Notes'); if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; $head[$h][2] = 'note'; $h++; - } + } require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref); + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + $upload_dir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref); $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); - $nbLinks = Link::count($db, $object->element, $object->id); + $nbLinks = Link::count($db, $object->element, $object->id); $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ''.($nbFiles + $nbLinks).''; @@ -129,13 +129,13 @@ function propal_admin_prepare_head() $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php'; $head[$h][1] = $langs->trans("ExtraFields"); - $head[$h][2] = 'attributes'; - $h++; + $head[$h][2] = 'attributes'; + $h++; - $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php'; - $head[$h][1] = $langs->trans("ExtraFieldsLines"); - $head[$h][2] = 'attributeslines'; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFieldsLines"); + $head[$h][2] = 'attributeslines'; + $h++; complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove'); diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 81775bf8dbd..cf1d1793a88 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -37,7 +37,7 @@ function shipping_prepare_head($object) global $db, $langs, $conf, $user; // Load translation files required by the page - $langs->loadLangs(array("sendings", "deliveries")); + $langs->loadLangs(array("sendings", "deliveries")); $h = 0; $head = array(); @@ -53,8 +53,8 @@ function shipping_prepare_head($object) $object->fetchObjectLinked($object->id, $object->element); if (is_array($object->linkedObjectsIds['delivery']) && count($object->linkedObjectsIds['delivery']) > 0) // If there is a delivery { - // Take first one element of array - $tmp = reset($object->linkedObjectsIds['delivery']); + // Take first one element of array + $tmp = reset($object->linkedObjectsIds['delivery']); $head[$h][0] = DOL_URL_ROOT."/delivery/card.php?id=".$tmp; $head[$h][1] = $langs->trans("DeliveryCard"); @@ -65,34 +65,34 @@ function shipping_prepare_head($object) if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { - $objectsrc = $object; - if ($object->origin == 'commande' && $object->origin_id > 0) - { - $objectsrc = new Commande($db); - $objectsrc->fetch($object->origin_id); - } - $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external')); - $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id; - $head[$h][1] = $langs->trans("ContactsAddresses"); + $objectsrc = $object; + if ($object->origin == 'commande' && $object->origin_id > 0) + { + $objectsrc = new Commande($db); + $objectsrc->fetch($object->origin_id); + } + $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external')); + $head[$h][0] = DOL_URL_ROOT."/expedition/contact.php?id=".$object->id; + $head[$h][1] = $langs->trans("ContactsAddresses"); if ($nbContact > 0) $head[$h][1] .= ''.$nbContact.''; - $head[$h][2] = 'contact'; - $h++; + $head[$h][2] = 'contact'; + $h++; } require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; $upload_dir = $conf->commande->dir_output."/".dol_sanitizeFileName($object->ref); $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); - $nbLinks = Link::count($db, $object->element, $object->id); + $nbLinks = Link::count($db, $object->element, $object->id); $head[$h][0] = DOL_URL_ROOT.'/expedition/document.php?id='.$object->id; $head[$h][1] = $langs->trans('Documents'); if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ''.($nbFiles + $nbLinks).''; $head[$h][2] = 'documents'; $h++; - $nbNote = 0; - if (!empty($object->note_private)) $nbNote++; - if (!empty($object->note_public)) $nbNote++; + $nbNote = 0; + if (!empty($object->note_private)) $nbNote++; + if (!empty($object->note_public)) $nbNote++; $head[$h][0] = DOL_URL_ROOT."/expedition/note.php?id=".$object->id; $head[$h][1] = $langs->trans("Notes"); if ($nbNote > 0) $head[$h][1] .= ''.$nbNote.''; @@ -101,8 +101,8 @@ function shipping_prepare_head($object) // Show more tabs from modules // Entries must be declared in modules descriptor with line - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab - // $this->tabs = array('entity:-tabname); to remove a tab + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove'); @@ -122,7 +122,7 @@ function delivery_prepare_head($object) global $langs, $db, $conf, $user; // Load translation files required by the page - $langs->loadLangs(array("sendings", "deliveries")); + $langs->loadLangs(array("sendings", "deliveries")); $h = 0; $head = array(); @@ -195,7 +195,7 @@ function delivery_prepare_head($object) $object->id = $tmpobject->id; - complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery'); + complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove'); @@ -262,7 +262,7 @@ function show_list_sending_receive($origin, $origin_id, $filter = '') print ''.$langs->trans("QtyPreparedOrShipped").''; if (!empty($conf->stock->enabled)) { - print ''.$langs->trans("Warehouse").''; + print ''.$langs->trans("Warehouse").''; } /*TODO Add link to expeditiondet_batch if (! empty($conf->productbatch->enabled)) @@ -371,13 +371,13 @@ function show_list_sending_receive($origin, $origin_id, $filter = '') // Warehouse if (!empty($conf->stock->enabled)) { - print ''; - if ($objp->warehouse_id > 0) - { - $warehousestatic->fetch($objp->warehouse_id); - print $warehousestatic->getNomUrl(1); - } - print ''; + print ''; + if ($objp->warehouse_id > 0) + { + $warehousestatic->fetch($objp->warehouse_id); + print $warehousestatic->getNomUrl(1); + } + print ''; } // Batch number managment diff --git a/htdocs/core/modules/delivery/mod_delivery_saphir.php b/htdocs/core/modules/delivery/mod_delivery_saphir.php index 10a979d4ee2..df1a15598b1 100644 --- a/htdocs/core/modules/delivery/mod_delivery_saphir.php +++ b/htdocs/core/modules/delivery/mod_delivery_saphir.php @@ -32,9 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php'; class mod_delivery_saphir extends ModeleNumRefDeliveryOrder { /** - * Dolibarr version of the loaded document - * @var string - */ + * Dolibarr version of the loaded document + * @var string + */ public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' /** @@ -55,14 +55,14 @@ class mod_delivery_saphir extends ModeleNumRefDeliveryOrder public $name = 'Saphir'; - /** - * Returns the description of the numbering model - * - * @return string Texte descripif - */ - public function info() - { - global $conf, $langs, $db; + /** + * Returns the description of the numbering model + * + * @return string Texte descripif + */ + public function info() + { + global $conf, $langs, $db; $langs->load("bills"); @@ -93,28 +93,28 @@ class mod_delivery_saphir extends ModeleNumRefDeliveryOrder $texte .= ''; return $texte; - } + } - /** - * Return an example of number - * - * @return string Example - */ - public function getExample() - { - global $conf, $langs, $mysoc; + /** + * Return an example of number + * + * @return string Example + */ + public function getExample() + { + global $conf, $langs, $mysoc; - $old_code_client = $mysoc->code_client; - $mysoc->code_client = 'CCCCCCCCCC'; + $old_code_client = $mysoc->code_client; + $mysoc->code_client = 'CCCCCCCCCC'; $numExample = $this->getNextValue($mysoc, ''); - $mysoc->code_client = $old_code_client; + $mysoc->code_client = $old_code_client; if (!$numExample) { $numExample = $langs->trans('NotConfigured'); } return $numExample; - } + } /** @@ -124,8 +124,8 @@ class mod_delivery_saphir extends ModeleNumRefDeliveryOrder * @param Object $object Object delivery * @return string Value if OK, 0 if KO */ - public function getNextValue($objsoc, $object) - { + public function getNextValue($objsoc, $object) + { global $db, $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -142,33 +142,33 @@ class mod_delivery_saphir extends ModeleNumRefDeliveryOrder $numFinal = get_next_value($db, $mask, 'delivery', 'ref', '', $objsoc, $object->date_livraison); return $numFinal; - } + } /** * Return next free value * - * @param Societe $objsoc Object third party + * @param Societe $objsoc Object third party * @param string $objforref Object for number to search - * @return string Next free value - */ - public function getNumRef($objsoc, $objforref) - { - return $this->getNextValue($objsoc, $objforref); - } + * @return string Next free value + */ + public function getNumRef($objsoc, $objforref) + { + return $this->getNextValue($objsoc, $objforref); + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return next free ref - * - * @param Societe $objsoc Object thirdparty - * @param Object $object Objet livraison - * @return string Texte descripif - */ - public function delivery_get_num($objsoc = 0, $object = '') - { - // phpcs:enable - return $this->getNextValue($objsoc, $object); - } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return next free ref + * + * @param Societe $objsoc Object thirdparty + * @param Object $object Objet livraison + * @return string Texte descripif + */ + public function delivery_get_num($objsoc = 0, $object = '') + { + // phpcs:enable + return $this->getNextValue($objsoc, $object); + } } diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 65172c88372..d9cde97c303 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -41,8 +41,8 @@ if (!empty($conf->expedition_bon->enabled)) if (!empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.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'; } // Load translation files required by the page @@ -126,8 +126,8 @@ if ($action == 'add') $action = 'create'; } } elseif ($action == 'confirm_valid' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) ) { $result = $object->valid($user); @@ -310,13 +310,13 @@ if ($action == 'create') // Create. Seems to no be used if ($typeobject == 'commande' && $expedition->origin_id > 0 && !empty($conf->commande->enabled)) { - $objectsrc = new Commande($db); - $objectsrc->fetch($expedition->origin_id); + $objectsrc = new Commande($db); + $objectsrc->fetch($expedition->origin_id); } if ($typeobject == 'propal' && $expedition->origin_id > 0 && !empty($conf->propal->enabled)) { - $objectsrc = new Propal($db); - $objectsrc->fetch($expedition->origin_id); + $objectsrc = new Propal($db); + $objectsrc->fetch($expedition->origin_id); } // Shipment card @@ -331,35 +331,35 @@ if ($action == 'create') // Create. Seems to no be used $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$expedition->thirdparty->getNomUrl(1); // Project if (!empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if (0) { // Do not change on shipment - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; - } - if ($action == 'classify') { - // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $expedition->id, $expedition->socid, $expedition->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= '
'; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($expedition->socid, $expedition->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= '
'; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$expedition->id, $expedition->socid, $expedition->fk_project, 'none', 0, 0, 0, 1); - } - } else { - $morehtmlref .= ' : '; - if (!empty($objectsrc->fk_project)) { - $proj = new Project($db); - $proj->fetch($objectsrc->fk_project); - $morehtmlref .= ''; - $morehtmlref .= $proj->ref; - $morehtmlref .= ''; - } else { - $morehtmlref .= ''; - } - } + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if (0) { // Do not change on shipment + if ($action != 'classify') { + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; + } + if ($action == 'classify') { + // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $expedition->id, $expedition->socid, $expedition->fk_project, 'projectid', 0, 0, 1, 1); + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects($expedition->socid, $expedition->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); + $morehtmlref .= ''; + $morehtmlref .= '
'; + } else { + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$expedition->id, $expedition->socid, $expedition->fk_project, 'none', 0, 0, 0, 1); + } + } else { + $morehtmlref .= ' : '; + if (!empty($objectsrc->fk_project)) { + $proj = new Project($db); + $proj->fetch($objectsrc->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } } $morehtmlref .= ''; @@ -371,7 +371,7 @@ if ($action == 'create') // Create. Seems to no be used print '
'; print '
'; - print ''; + print '
'; // Shipment /* @@ -454,21 +454,21 @@ if ($action == 'create') // Create. Seems to no be used if (!empty($conf->incoterm->enabled)) { print ''; - print ''; + print ''; + print ''; } /* A delivery note should be just more properties of a shipment, so notes are on shipment @@ -690,9 +690,9 @@ if ($action == 'create') // Create. Seems to no be used $shipment = new Expedition($db); $shipment->fetch($object->origin_id); - // Show links to link elements - //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); - $somethingshown = $form->showLinkedObjectBlock($object, ''); + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); + $somethingshown = $form->showLinkedObjectBlock($object, ''); } diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index c5b62d4233d..74ba0f86de0 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -88,8 +88,8 @@ class Delivery extends CommonObject public $date_delivery; /** - * @var integer|string date_creation - */ + * @var integer|string date_creation + */ public $date_creation; /** @@ -108,7 +108,7 @@ class Delivery extends CommonObject * * @param DoliDB $db Database handler */ - public function __construct($db) + public function __construct($db) { $this->db = $db; $this->lines = array(); @@ -126,7 +126,7 @@ class Delivery extends CommonObject * @param User $user Objet du user qui cree * @return int <0 si erreur, id delivery cree si ok */ - public function create($user) + public function create($user) { global $conf; @@ -136,7 +136,7 @@ class Delivery extends CommonObject $error = 0; - $now = dol_now(); + $now = dol_now(); /* Delivery note as draft On positionne en mode draft le bon de livraison */ $this->draft = 1; @@ -170,8 +170,8 @@ class Delivery extends CommonObject $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); $sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null"); $sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null"); - $sql .= ", ".(int) $this->fk_incoterms; - $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; + $sql .= ", ".(int) $this->fk_incoterms; + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; $sql .= ")"; dol_syslog("Delivery::create", LOG_DEBUG); @@ -256,7 +256,7 @@ class Delivery extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a line * @@ -266,9 +266,9 @@ class Delivery extends CommonObject * @param string $description Description * @return int <0 if KO, >0 if OK */ - public function create_line($origin_id, $qty, $fk_product, $description) - { - // phpcs:enable + public function create_line($origin_id, $qty, $fk_product, $description) + { + // phpcs:enable $error = 0; $idprod = $fk_product; $j = 0; @@ -298,7 +298,7 @@ class Delivery extends CommonObject * @param int $id Id of object to load * @return integer */ - public function fetch($id) + public function fetch($id) { global $conf; @@ -306,8 +306,8 @@ class Delivery extends CommonObject $sql .= " l.total_ht, l.fk_statut, l.fk_user_valid, l.note_private, l.note_public"; $sql .= ", l.date_delivery, l.fk_address, l.model_pdf"; $sql .= ", el.fk_source as origin_id, el.sourcetype as origin"; - $sql .= ', l.fk_incoterms, l.location_incoterms'; - $sql .= ", i.libelle as label_incoterms"; + $sql .= ', l.fk_incoterms, l.location_incoterms'; + $sql .= ", i.libelle as label_incoterms"; $sql .= " FROM ".MAIN_DB_PREFIX."delivery as l"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = l.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON l.fk_incoterms = i.rowid'; @@ -374,14 +374,14 @@ class Delivery extends CommonObject /** * Validate object and update stock if option enabled * - * @param User $user Object user that validate - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int + * @param User $user Object user that validate + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int */ - public function valid($user, $notrigger = 0) + public function valid($user, $notrigger = 0) { global $conf, $langs; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; dol_syslog(get_class($this)."::valid begin"); @@ -389,8 +389,8 @@ class Delivery extends CommonObject $error = 0; - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) { if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) { @@ -409,12 +409,12 @@ class Delivery extends CommonObject $soc->fetch($this->socid); if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life - { - $numref = $objMod->delivery_get_num($soc, $this); - } else { - $numref = $this->ref; - } - $this->newref = dol_sanitizeFileName($numref); + { + $numref = $objMod->delivery_get_num($soc, $this); + } else { + $numref = $this->ref; + } + $this->newref = dol_sanitizeFileName($numref); // Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice. $sql = "SELECT ref"; @@ -442,24 +442,24 @@ class Delivery extends CommonObject $sql .= " AND fk_statut = 0"; $resql = $this->db->query($sql); - if (!$resql) - { - dol_print_error($this->db); - $this->error = $this->db->lasterror(); - $error++; - } + if (!$resql) + { + dol_print_error($this->db); + $this->error = $this->db->lasterror(); + $error++; + } - if (!$error && !$notrigger) - { - // Call trigger - $result = $this->call_trigger('DELIVERY_VALIDATE', $user); - if ($result < 0) $error++; - // End call triggers - } + if (!$error && !$notrigger) + { + // Call trigger + $result = $this->call_trigger('DELIVERY_VALIDATE', $user); + if ($result < 0) $error++; + // End call triggers + } if (!$error) { - $this->oldref = $this->ref; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -481,17 +481,17 @@ class Delivery extends CommonObject if (@rename($dirsource, $dirdest)) { - dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref - $listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { - $dirsource = $fileentry['name']; - $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource = $fileentry['path'].'/'.$dirsource; - $dirdest = $fileentry['path'].'/'.$dirdest; - @rename($dirsource, $dirdest); - } + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) + { + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; + @rename($dirsource, $dirdest); + } } } } @@ -506,14 +506,14 @@ class Delivery extends CommonObject dol_syslog(get_class($this)."::valid ok"); } - if (!$error) - { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } + if (!$error) + { + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return -1; + } } } } else { @@ -523,7 +523,7 @@ class Delivery extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Creating the delivery slip from an existing shipment * @@ -531,9 +531,9 @@ class Delivery extends CommonObject * @param int $sending_id Id of the expedition that serves as a model * @return integer */ - public function create_from_sending($user, $sending_id) + public function create_from_sending($user, $sending_id) { - // phpcs:enable + // phpcs:enable $expedition = new Expedition($this->db); $result = $expedition->fetch($sending_id); @@ -569,7 +569,7 @@ class Delivery extends CommonObject return $this->create($user); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update a livraison line (only extrafields) * @@ -577,9 +577,9 @@ class Delivery extends CommonObject * @param array $array_options extrafields array * @return int <0 if KO, >0 if OK */ - public function update_line($id, $array_options = 0) + public function update_line($id, $array_options = 0) { - // phpcs:enable + // phpcs:enable global $conf; $error = 0; @@ -609,7 +609,7 @@ class Delivery extends CommonObject * @param int $qty Qty * @return void */ - public function addline($origin_id, $qty) + public function addline($origin_id, $qty) { $num = count($this->lines); $line = new DeliveryLine($this->db); @@ -626,7 +626,7 @@ class Delivery extends CommonObject * @param int $lineid Line id * @return integer|null */ - public function deleteline($lineid) + public function deleteline($lineid) { if ($this->statut == 0) { @@ -649,11 +649,11 @@ class Delivery extends CommonObject * * @return integer */ - public function delete() + public function delete() { global $conf, $langs, $user; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $this->db->begin(); $error = 0; @@ -697,14 +697,14 @@ class Delivery extends CommonObject } } - // Call trigger - $result = $this->call_trigger('DELIVERY_DELETE', $user); - if ($result < 0) - { - $this->db->rollback(); - return -4; - } - // End call triggers + // Call trigger + $result = $this->call_trigger('DELIVERY_DELETE', $user); + if ($result < 0) + { + $this->db->rollback(); + return -4; + } + // End call triggers return 1; } else { @@ -728,10 +728,10 @@ class Delivery extends CommonObject * Return clicable name (with picto eventually) * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string Chaine avec URL */ - public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1) + public function getNomUrl($withpicto = 0, $save_lastsearch_value = -1) { global $langs; @@ -742,16 +742,16 @@ class Delivery extends CommonObject $url = DOL_URL_ROOT.'/delivery/card.php?id='.$this->id; - //if ($option !== 'nolink') - //{ - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; - //} + //if ($option !== 'nolink') + //{ + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + //} - $linkstart = ''; + $linkstart = ''; $linkend = ''; if ($withpicto) $result .= ($linkstart.img_object($label, $this->picto, 'class="classfortooltip"').$linkend); @@ -760,15 +760,15 @@ class Delivery extends CommonObject return $result; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load lines * * @return void */ - public function fetch_lines() + public function fetch_lines() { - // phpcs:enable + // phpcs:enable $this->lines = array(); $sql = "SELECT ld.rowid, ld.fk_product, ld.description, ld.subprice, ld.total_ht, ld.qty as qty_shipped, ld.fk_origin_line, "; @@ -844,12 +844,12 @@ class Delivery extends CommonObject * @param int $mode Mode * @return string Label */ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) { return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Renvoi le libelle d'un statut donne * @@ -857,9 +857,9 @@ class Delivery extends CommonObject * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label */ - public function LibStatut($status, $mode) + public function LibStatut($status, $mode) { - // phpcs:enable + // phpcs:enable global $langs; if (empty($this->labelStatus) || empty($this->labelStatusShort)) @@ -883,19 +883,19 @@ class Delivery extends CommonObject /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void */ - public function initAsSpecimen() + public function initAsSpecimen() { global $user, $langs, $conf; $now = dol_now(); - // Load array of products prodids + // Load array of products prodids $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; @@ -946,7 +946,7 @@ class Delivery extends CommonObject * @return array Product remaining to be delivered * TODO use new function */ - public function getRemainingDelivered() + public function getRemainingDelivered() { global $langs; @@ -1148,13 +1148,13 @@ class DeliveryLine extends CommonObjectLine public $product_ref; public $product_label; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - } + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index d86e177034e..229031ff56a 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -159,8 +159,8 @@ class Expedition extends CommonObject public $date_shipping; /** - * @var integer|string date_creation - */ + * @var integer|string date_creation + */ public $date_creation; /** @@ -171,7 +171,7 @@ class Expedition extends CommonObject public $meths; public $listmeths; // List of carriers - /** + /** * Draft status */ const STATUS_DRAFT = 0; @@ -441,7 +441,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a expedition line * @@ -473,7 +473,7 @@ class Expedition extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create the detail (eat-by date) of the expedition line * @@ -483,7 +483,7 @@ class Expedition extends CommonObject */ public function create_line_batch($line_ext, $array_options = 0) { - // phpcs:enable + // phpcs:enable $error = 0; $stockLocationQty = array(); // associated array with batch qty in stock location @@ -537,7 +537,7 @@ class Expedition extends CommonObject if (empty($id) && empty($ref) && empty($ref_ext)) return -1; $sql = "SELECT e.rowid, e.entity, 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, e.fk_projet as fk_project, e.billed"; - $sql .= ", e.date_valid"; + $sql .= ", e.date_valid"; $sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; $sql .= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery"; $sql .= ", e.fk_shipping_method, e.tracking_number"; @@ -574,7 +574,7 @@ class Expedition extends CommonObject $this->statut = $obj->fk_statut; $this->user_author_id = $obj->fk_user_author; $this->date_creation = $this->db->jdate($obj->date_creation); - $this->date_valid = $this->db->jdate($obj->date_valid); + $this->date_valid = $this->db->jdate($obj->date_valid); $this->date = $this->db->jdate($obj->date_expedition); // TODO deprecated $this->date_expedition = $this->db->jdate($obj->date_expedition); // TODO deprecated $this->date_shipping = $this->db->jdate($obj->date_expedition); // Date real @@ -868,7 +868,7 @@ class Expedition extends CommonObject } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a delivery receipt from a shipment * @@ -877,7 +877,7 @@ class Expedition extends CommonObject */ public function create_delivery($user) { - // phpcs:enable + // phpcs:enable global $conf; if ($conf->delivery_note->enabled) @@ -974,7 +974,7 @@ class Expedition extends CommonObject $this->lines[$num] = $line; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add a shipment line with batch record * @@ -984,7 +984,7 @@ class Expedition extends CommonObject */ public function addline_batch($dbatch, $array_options = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs; $num = count($this->lines); @@ -1154,7 +1154,7 @@ class Expedition extends CommonObject * Cancel shipment. * * @param int $notrigger Disable triggers - * @param bool $also_update_stock true if the stock should be increased back (false by default) + * @param bool $also_update_stock true if the stock should be increased back (false by default) * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ public function cancel($notrigger = 0, $also_update_stock = false) @@ -1360,7 +1360,7 @@ class Expedition extends CommonObject * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) * * @param int $notrigger Disable triggers - * @param bool $also_update_stock true if the stock should be increased back (false by default) + * @param bool $also_update_stock true if the stock should be increased back (false by default) * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ public function delete($notrigger = 0, $also_update_stock = false) @@ -1474,9 +1474,9 @@ class Expedition extends CommonObject if (!$error) { - $main = MAIN_DB_PREFIX.'expeditiondet'; - $ef = $main."_extrafields"; - $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.")"; + $main = MAIN_DB_PREFIX.'expeditiondet'; + $ef = $main."_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.")"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql .= " WHERE fk_expedition = ".$this->id; @@ -1487,9 +1487,9 @@ class Expedition extends CommonObject $res = $this->deleteObjectLinked(); if ($res < 0) $error++; - // delete extrafields - $res = $this->deleteExtraFields(); - if ($res < 0) $error++; + // delete extrafields + $res = $this->deleteExtraFields(); + if ($res < 0) $error++; if (!$error) { @@ -1570,7 +1570,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load lines * @@ -1578,7 +1578,7 @@ class Expedition extends CommonObject */ public function fetch_lines() { - // phpcs:enable + // phpcs:enable global $conf, $mysoc; // TODO: recuperer les champs du document associe a part $this->lines = array(); @@ -1854,7 +1854,7 @@ class Expedition extends CommonObject return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of a status * @@ -1864,8 +1864,8 @@ class Expedition extends CommonObject */ public function LibStatut($status, $mode) { - // phpcs:enable - global $langs; + // phpcs:enable + global $langs; $labelStatus = $langs->trans($this->statuts[$status]); $labelStatusShort = $langs->trans($this->statutshorts[$status]); @@ -2002,7 +2002,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch deliveries method and return an array. Load array this->meths(rowid=>label). * @@ -2030,7 +2030,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch all deliveries method and return an array. Load array this->listmeths. * @@ -2039,7 +2039,7 @@ class Expedition extends CommonObject */ public function list_delivery_methods($id = '') { - // phpcs:enable + // phpcs:enable global $langs; $this->listmeths = array(); @@ -2066,7 +2066,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update/create delivery method. * @@ -2110,7 +2110,7 @@ class Expedition extends CommonObject $resql = $this->db->query($sql); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * DesActivate delivery method. * @@ -2308,7 +2308,7 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on) * @@ -2316,7 +2316,7 @@ class Expedition extends CommonObject */ public function set_billed() { - // phpcs:enable + // phpcs:enable global $user; $error = 0; @@ -2450,13 +2450,13 @@ class Expedition extends CommonObject } } - if (!$error) { + if (!$error) { // Call trigger $result = $this->call_trigger('SHIPPING_REOPEN', $user); if ($result < 0) { $error++; } - } + } } else { $error++; $this->errors[] = $this->db->lasterror(); @@ -2482,7 +2482,7 @@ class Expedition extends CommonObject * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) @@ -2550,8 +2550,8 @@ class ExpeditionLigne extends CommonObjectLine public $origin_line_id; /** - * @var int ID - */ + * @var int ID + */ public $fk_origin_line; /** @@ -2560,42 +2560,42 @@ class ExpeditionLigne extends CommonObjectLine public $fk_expedition; /** - * @var DoliDB Database handler. - */ - public $db; + * @var DoliDB Database handler. + */ + public $db; - /** - * @var float qty asked From llx_expeditiondet - */ - public $qty; + /** + * @var float qty asked From llx_expeditiondet + */ + public $qty; - /** - * @var float qty shipped - */ - public $qty_shipped; + /** + * @var float qty shipped + */ + public $qty_shipped; - /** - * @var int Id of product - */ - public $fk_product; - public $detail_batch; + /** + * @var int Id of product + */ + public $fk_product; + public $detail_batch; - /** - * @var int Id of warehouse - */ + /** + * @var int Id of warehouse + */ public $entrepot_id; - /** - * @var float qty asked From llx_commandedet or llx_propaldet - */ + /** + * @var float qty asked From llx_commandedet or llx_propaldet + */ public $qty_asked; - /** - * @deprecated - * @see $product_ref - */ - public $ref; + /** + * @deprecated + * @see $product_ref + */ + public $ref; /** * @var string product ref @@ -2608,87 +2608,87 @@ class ExpeditionLigne extends CommonObjectLine */ public $libelle; - /** - * @var string product label - */ + /** + * @var string product label + */ public $product_label; - /** - * @var string product description - * @deprecated - * @see $product_desc - */ - public $desc; + /** + * @var string product description + * @deprecated + * @see $product_desc + */ + public $desc; - /** - * @var string product description - */ + /** + * @var string product description + */ public $product_desc; - /** - * @var int rang of line - */ - public $rang; + /** + * @var int rang of line + */ + public $rang; - /** - * @var float weight - */ - public $weight; - public $weight_units; + /** + * @var float weight + */ + public $weight; + public $weight_units; - /** - * @var float weight - */ - public $length; - public $length_units; + /** + * @var float weight + */ + public $length; + public $length_units; - /** - * @var float weight - */ - public $surface; - public $surface_units; + /** + * @var float weight + */ + public $surface; + public $surface_units; - /** - * @var float weight - */ - public $volume; - public $volume_units; + /** + * @var float weight + */ + public $volume; + public $volume_units; // Invoicing public $remise_percent; - public $tva_tx; + public $tva_tx; - /** - * @var float total without tax - */ - public $total_ht; + /** + * @var float total without tax + */ + public $total_ht; - /** - * @var float total with tax - */ - public $total_ttc; + /** + * @var float total with tax + */ + public $total_ttc; - /** - * @var float total vat - */ - public $total_tva; + /** + * @var float total vat + */ + public $total_tva; - /** - * @var float total localtax 1 - */ - public $total_localtax1; + /** + * @var float total localtax 1 + */ + public $total_localtax1; - /** - * @var float total localtax 2 - */ - public $total_localtax2; + /** + * @var float total localtax 2 + */ + public $total_localtax2; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ + /** + * Constructor + * + * @param DoliDB $db Database handler + */ public function __construct($db) { $this->db = $db; diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 4d4dd365c5f..b487202e26a 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -124,100 +124,100 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } */ - if ($action == 'setmode' && $user->rights->commande->creer) - { - $object = new Commande($db); - $object->fetch($id); - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($action == 'setmode' && $user->rights->commande->creer) + { + $object = new Commande($db); + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - if ($action == 'setavailability' && $user->rights->commande->creer) { - $object = new Commande($db); - $object->fetch($id); - $result = $object->availability(GETPOST('availability_id')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($action == 'setavailability' && $user->rights->commande->creer) { + $object = new Commande($db); + $object->fetch($id); + $result = $object->availability(GETPOST('availability_id')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - if ($action == 'setdemandreason' && $user->rights->commande->creer) { - $object = new Commande($db); - $object->fetch($id); - $result = $object->demand_reason(GETPOST('demand_reason_id')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($action == 'setdemandreason' && $user->rights->commande->creer) { + $object = new Commande($db); + $object->fetch($id); + $result = $object->demand_reason(GETPOST('demand_reason_id')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - if ($action == 'setconditions' && $user->rights->commande->creer) - { - $object = new Commande($db); - $object->fetch($id); - $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + if ($action == 'setconditions' && $user->rights->commande->creer) + { + $object = new Commande($db); + $object->fetch($id); + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - // 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'); - } - } + // 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'); + } + } - // shipping method - if ($action == 'setshippingmethod' && $user->rights->commande->creer) { - $object = new Commande($db); - $object->fetch($id); - $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + // shipping method + if ($action == 'setshippingmethod' && $user->rights->commande->creer) { + $object = new Commande($db); + $object->fetch($id); + $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - // warehouse - if ($action == 'setwarehouse' && $user->rights->commande->creer) { - $object = new Commande($db); - $object->fetch($id); - $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } + // warehouse + if ($action == 'setwarehouse' && $user->rights->commande->creer) { + $object = new Commande($db); + $object->fetch($id); + $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); + } - if ($action == 'update_extras') - { - $object->oldcopy = dol_clone($object); + if ($action == 'update_extras') + { + $object->oldcopy = dol_clone($object); - // Fill array 'array_options' with data from update form - $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + // Fill array 'array_options' with data from update form + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); + if ($ret < 0) $error++; - if (!$error) - { - // Actions on extra fields - $result = $object->insertExtraFields('SHIPMENT_MODIFY'); + if (!$error) + { + // Actions on extra fields + $result = $object->insertExtraFields('SHIPMENT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } + } - if ($error) - $action = 'edit_extras'; - } + if ($error) + $action = 'edit_extras'; + } - if ($action == 'set_thirdparty' && $user->rights->commande->creer) - { - $object->fetch($id); - $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY'); + if ($action == 'set_thirdparty' && $user->rights->commande->creer) + { + $object->fetch($id); + $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY'); - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit(); - } + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit(); + } - include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; } /* @@ -280,61 +280,61 @@ if ($id > 0 || !empty($ref)) // 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); - // Project - if (!empty($conf->projet->enabled)) - { - $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->commande->creer) - { - if ($action != 'classify') { + // Thirdparty + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$soc->getNomUrl(1); + // 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 .= ''; + } + 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 '
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->expedition->delivery->creer) print ''.img_edit().''; - else print ' '; - print '
'; - print '
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->expedition->delivery->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print '
'; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); } else { 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 '
'; // Discounts for third party - 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 - $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 (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; - } + 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 + $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 (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; + } print ''; print ''; @@ -380,7 +380,7 @@ if ($id > 0 || !empty($ref)) } else { print dol_print_date($object->date_livraison, 'dayhour'); 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 ''; @@ -390,43 +390,43 @@ if ($id > 0 || !empty($ref)) //print ''; print ''; - // Shipping Method - print ''; - print ''; + // Shipping Method + print ''; + print ''; - // Warehouse - if (!empty($conf->stock->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->stock->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 /* @@ -502,14 +502,14 @@ if ($id > 0 || !empty($ref)) $totalVolume = $tmparray['volume']; if ($totalWeight || $totalVolume) { - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; } // TODO How record was recorded OrderMode (llx_c_input_method) @@ -517,22 +517,22 @@ if ($id > 0 || !empty($ref)) // Incoterms if (!empty($conf->incoterm->enabled)) { - print ''; - print ''; + print ''; + print ''; } $expe = new Expedition($db); @@ -553,20 +553,20 @@ if ($id > 0 || !empty($ref)) if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { - // Multicurrency Amount HT - print ''; - print ''; - print ''; + // Multicurrency Amount HT + print ''; + print ''; + print ''; - // Multicurrency Amount VAT - print ''; - print ''; - print ''; + // Multicurrency Amount VAT + print ''; + print ''; + print ''; - // Multicurrency Amount TTC - print ''; - print ''; - print ''; + // Multicurrency Amount TTC + print ''; + print ''; + print ''; } // Total HT @@ -581,13 +581,13 @@ if ($id > 0 || !empty($ref)) // Amount Local Taxes if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1 { - print ''; - print ''; + print ''; + print ''; } if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2 IRPF { - print ''; - print ''; + print ''; + print ''; } // Total TTC @@ -676,8 +676,8 @@ if ($id > 0 || !empty($ref)) $object->fetch_thirdparty(); $prod = new Product($db); - $prod->id = $objp->fk_product; - $prod->entity = $objp->entity; + $prod->id = $objp->fk_product; + $prod->entity = $objp->entity; $prod->getMultiLangs(); $outputlangs = $langs; @@ -700,25 +700,25 @@ if ($id > 0 || !empty($ref)) $product_static->type = $type; $product_static->id = $objp->fk_product; $product_static->ref = $objp->ref; - $product_static->entity = $objp->entity; + $product_static->entity = $objp->entity; - $product_static->weight = $objp->weight; - $product_static->weight_units = $objp->weight_units; - $product_static->length = $objp->length; - $product_static->length_units = $objp->length_units; - $product_static->width = $objp->width; - $product_static->width_units = $objp->width_units; - $product_static->height = $objp->height; - $product_static->height_units = $objp->height_units; - $product_static->surface = $objp->surface; - $product_static->surface_units = $objp->surface_units; - $product_static->volume = $objp->volume; - $product_static->volume_units = $objp->volume_units; + $product_static->weight = $objp->weight; + $product_static->weight_units = $objp->weight_units; + $product_static->length = $objp->length; + $product_static->length_units = $objp->length_units; + $product_static->width = $objp->width; + $product_static->width_units = $objp->width_units; + $product_static->height = $objp->height; + $product_static->height_units = $objp->height_units; + $product_static->surface = $objp->surface; + $product_static->surface_units = $objp->surface_units; + $product_static->volume = $objp->volume; + $product_static->volume_units = $objp->volume_units; $text = $product_static->getNomUrl(1); $text .= ' - '.$label; $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($objp->description)).'
'; - $description .= $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80); + $description .= $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80); print $form->textwithtooltip($text, $description, 3, '', '', $i); // Show range @@ -845,8 +845,8 @@ if ($id > 0 || !empty($ref)) { print '
'; - // Bouton expedier sans gestion des stocks - if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) + // Bouton expedier sans gestion des stocks + if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) { if ($user->rights->expedition->creer) { @@ -863,24 +863,24 @@ if ($id > 0 || !empty($ref)) } - // Bouton expedier avec gestion des stocks + // Bouton expedier avec gestion des stocks - if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT) - { - print $langs->trans("ValidateOrderFirstBeforeShipment"); - } + if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT) + { + print $langs->trans("ValidateOrderFirstBeforeShipment"); + } if (!empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) { if ($user->rights->expedition->creer) { //print load_fiche_titre($langs->trans("CreateShipment")); - print '
'; + print '
'; print '
'; print ''; //print ''; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index d3780d412ea..8d5809dff73 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -2219,37 +2219,37 @@ class FactureFournisseur extends CommonInvoice if ($user->socid) $sql .= ' AND ff.fk_soc = '.$user->socid; if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; - $resql = $this->db->query($sql); - if ($resql) - { - $langs->load("bills"); - $now = dol_now(); + $resql = $this->db->query($sql); + if ($resql) + { + $langs->load("bills"); + $now = dol_now(); - $response = new WorkboardResponse(); - $response->warning_delay = $conf->facture->fournisseur->warning_delay / 60 / 60 / 24; - $response->label = $langs->trans("SupplierBillsToPay"); - $response->labelShort = $langs->trans("StatusToPay"); + $response = new WorkboardResponse(); + $response->warning_delay = $conf->facture->fournisseur->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("SupplierBillsToPay"); + $response->labelShort = $langs->trans("StatusToPay"); - $response->url = DOL_URL_ROOT.'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills'; - $response->img = img_object($langs->trans("Bills"), "bill"); + $response->url = DOL_URL_ROOT.'/fourn/facture/list.php?search_status=1&mainmenu=billing&leftmenu=suppliers_bills'; + $response->img = img_object($langs->trans("Bills"), "bill"); - $facturestatic = new FactureFournisseur($this->db); + $facturestatic = new FactureFournisseur($this->db); - while ($obj = $this->db->fetch_object($resql)) - { - $response->nbtodo++; + while ($obj = $this->db->fetch_object($resql)) + { + $response->nbtodo++; - $facturestatic->date_echeance = $this->db->jdate($obj->datefin); - $facturestatic->statut = $obj->fk_statut; + $facturestatic->date_echeance = $this->db->jdate($obj->datefin); + $facturestatic->statut = $obj->fk_statut; - if ($facturestatic->hasDelay()) { - $response->nbtodolate++; + if ($facturestatic->hasDelay()) { + $response->nbtodolate++; $response->url_late = DOL_URL_ROOT.'/fourn/facture/list.php?option=late&mainmenu=billing&leftmenu=suppliers_bills'; - } - } - $this->db->free($resql); - return $response; - } else { + } + } + $this->db->free($resql); + return $response; + } else { dol_print_error($this->db); $this->error = $this->db->error(); return -1; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index c6208f1dd1b..7b41e7030b1 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -41,7 +41,7 @@ include_once 'inc.php'; if (!file_exists($conffile)) { - print 'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").'; + print 'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").'; } require_once $conffile; require_once $dolibarr_main_document_root.'/compta/facture/class/facture.class.php'; @@ -111,353 +111,353 @@ pHeader('', 'step5', GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'upg if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) { - print '

Database '.$langs->trans('DataMigration').'

'; + print '

Database '.$langs->trans('DataMigration').'

'; - print '
'.$langs->trans('Discounts').''; @@ -355,7 +355,7 @@ if ($id > 0 || !empty($ref)) print ''; print 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 '
'; - print ''; - if ($action != 'editshippingmethod' && $user->rights->expedition->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->expedition->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 '
'.$langs->trans("CalculatedWeight").''; - 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 '
'.$langs->trans("CalculatedVolume").''; - 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 '
'.$langs->trans("CalculatedWeight").''; + 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 '
'.$langs->trans("CalculatedVolume").''; + 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 '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->commande->creer) print ''.img_edit().''; - else print ' '; - print '
'; - print '
'; - if ($action != 'editincoterm') - { - print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); - } else { - 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 '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->commande->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print '
'; + if ($action != 'editincoterm') + { + print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); + } else { + 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 '
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).''.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).''.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).''.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).''.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'; + print '
'; - // If password is encoded, we decode it - if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) - { - require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; - if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) - { - $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); - $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass); - $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted - } else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); - } + // If password is encoded, we decode it + if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) + { + require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; + if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) + { + $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass); + $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass); + $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted + } else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass); + } - // $conf is already instancied inside inc.php - $conf->db->type = $dolibarr_main_db_type; - $conf->db->host = $dolibarr_main_db_host; - $conf->db->port = $dolibarr_main_db_port; - $conf->db->name = $dolibarr_main_db_name; - $conf->db->user = $dolibarr_main_db_user; - $conf->db->pass = $dolibarr_main_db_pass; + // $conf is already instancied inside inc.php + $conf->db->type = $dolibarr_main_db_type; + $conf->db->host = $dolibarr_main_db_host; + $conf->db->port = $dolibarr_main_db_port; + $conf->db->name = $dolibarr_main_db_name; + $conf->db->user = $dolibarr_main_db_user; + $conf->db->pass = $dolibarr_main_db_pass; - $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port); + $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port); - // Create the global $hookmanager object - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($db); - $hookmanager->initHooks(array('upgrade')); + // Create the global $hookmanager object + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($db); + $hookmanager->initHooks(array('upgrade')); - if (!$db->connected) - { - print ''; - dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR); - $error++; - } + if (!$db->connected) + { + print ''; + dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR); + $error++; + } - if (!$error) - { - if ($db->database_selected) - { - dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name); - } else { - $error++; - } - } + if (!$error) + { + if ($db->database_selected) + { + dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name); + } else { + $error++; + } + } - if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0; - $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; - if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = ''; - $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; + if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption = 0; + $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption; + if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey = ''; + $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey; - // Chargement config - if (!$error) - { - $conf->setValues($db); - // Reset forced setup after the setValues - if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); - $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; - } + // Chargement config + if (!$error) + { + $conf->setValues($db); + // Reset forced setup after the setValues + if (defined('SYSLOG_FILE')) $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE'); + $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; + } - /*************************************************************************************** + /*************************************************************************************** * * Migration of data * ***************************************************************************************/ - $db->begin(); + $db->begin(); - if (!$error) - { - // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE - // Version to install is DOL_VERSION - $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : '')); + if (!$error) + { + // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE + // Version to install is DOL_VERSION + $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : '')); - // Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec - // dans la 1ere colonne, la description de l'action a faire - // dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error' + // Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec + // dans la 1ere colonne, la description de l'action a faire + // dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error' - $versiontoarray = explode('.', $versionto); - $versionranarray = explode('.', DOL_VERSION); + $versiontoarray = explode('.', $versionto); + $versionranarray = explode('.', DOL_VERSION); - // Force to execute this at begin to avoid the new core code into Dolibarr to be broken. - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN birth date'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemployment date'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemploymentend date'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_range integer'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_c_exp_tax_cat integer'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN langs varchar(24)'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fieldcomputed text'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fielddefault varchar(255)'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX."extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'"; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN help text'; - $db->query($sql, 1); - $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL'; - $db->query($sql, 1); + // Force to execute this at begin to avoid the new core code into Dolibarr to be broken. + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN birth date'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemployment date'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemploymentend date'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_range integer'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_c_exp_tax_cat integer'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN langs varchar(24)'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fieldcomputed text'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fielddefault varchar(255)'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX."extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'"; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN help text'; + $db->query($sql, 1); + $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL'; + $db->query($sql, 1); - $afterversionarray = explode('.', '2.0.0'); - $beforeversionarray = explode('.', '2.7.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - // Script pour V2 -> V2.1 - migrate_paiements($db, $langs, $conf); + $afterversionarray = explode('.', '2.0.0'); + $beforeversionarray = explode('.', '2.7.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + // Script pour V2 -> V2.1 + migrate_paiements($db, $langs, $conf); - migrate_contracts_det($db, $langs, $conf); + migrate_contracts_det($db, $langs, $conf); - migrate_contracts_date1($db, $langs, $conf); + migrate_contracts_date1($db, $langs, $conf); - migrate_contracts_date2($db, $langs, $conf); + migrate_contracts_date2($db, $langs, $conf); - migrate_contracts_date3($db, $langs, $conf); + migrate_contracts_date3($db, $langs, $conf); - migrate_contracts_open($db, $langs, $conf); + migrate_contracts_open($db, $langs, $conf); - migrate_modeles($db, $langs, $conf); + migrate_modeles($db, $langs, $conf); - migrate_price_propal($db, $langs, $conf); + migrate_price_propal($db, $langs, $conf); - migrate_price_commande($db, $langs, $conf); + migrate_price_commande($db, $langs, $conf); - migrate_price_commande_fournisseur($db, $langs, $conf); + migrate_price_commande_fournisseur($db, $langs, $conf); - migrate_price_contrat($db, $langs, $conf); + migrate_price_contrat($db, $langs, $conf); - migrate_paiementfourn_facturefourn($db, $langs, $conf); + migrate_paiementfourn_facturefourn($db, $langs, $conf); - // Script pour V2.1 -> V2.2 - migrate_paiements_orphelins_1($db, $langs, $conf); + // Script pour V2.1 -> V2.2 + migrate_paiements_orphelins_1($db, $langs, $conf); - migrate_paiements_orphelins_2($db, $langs, $conf); + migrate_paiements_orphelins_2($db, $langs, $conf); - migrate_links_transfert($db, $langs, $conf); + migrate_links_transfert($db, $langs, $conf); - // Script pour V2.2 -> V2.4 - migrate_commande_expedition($db, $langs, $conf); + // Script pour V2.2 -> V2.4 + migrate_commande_expedition($db, $langs, $conf); - migrate_commande_livraison($db, $langs, $conf); + migrate_commande_livraison($db, $langs, $conf); - migrate_detail_livraison($db, $langs, $conf); + migrate_detail_livraison($db, $langs, $conf); - // Script pour V2.5 -> V2.6 - migrate_stocks($db, $langs, $conf); + // Script pour V2.5 -> V2.6 + migrate_stocks($db, $langs, $conf); - // Script pour V2.6 -> V2.7 - migrate_menus($db, $langs, $conf); + // Script pour V2.6 -> V2.7 + migrate_menus($db, $langs, $conf); - migrate_commande_deliveryaddress($db, $langs, $conf); + migrate_commande_deliveryaddress($db, $langs, $conf); - migrate_restore_missing_links($db, $langs, $conf); + migrate_restore_missing_links($db, $langs, $conf); - migrate_rename_directories($db, $langs, $conf, '/compta', '/banque'); + migrate_rename_directories($db, $langs, $conf, '/compta', '/banque'); - migrate_rename_directories($db, $langs, $conf, '/societe', '/mycompany'); - } + migrate_rename_directories($db, $langs, $conf, '/societe', '/mycompany'); + } - // Script for 2.8 - $afterversionarray = explode('.', '2.7.9'); - $beforeversionarray = explode('.', '2.8.9'); - //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx + // Script for 2.8 + $afterversionarray = explode('.', '2.7.9'); + $beforeversionarray = explode('.', '2.8.9'); + //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx - migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping'); + migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping'); - migrate_relationship_tables($db, $langs, $conf, 'pr_exp', 'fk_propal', 'propal', 'fk_expedition', 'shipping'); + migrate_relationship_tables($db, $langs, $conf, 'pr_exp', 'fk_propal', 'propal', 'fk_expedition', 'shipping'); - migrate_relationship_tables($db, $langs, $conf, 'pr_liv', 'fk_propal', 'propal', 'fk_livraison', 'delivery'); + migrate_relationship_tables($db, $langs, $conf, 'pr_liv', 'fk_propal', 'propal', 'fk_livraison', 'delivery'); - migrate_relationship_tables($db, $langs, $conf, 'co_liv', 'fk_commande', 'commande', 'fk_livraison', 'delivery'); + migrate_relationship_tables($db, $langs, $conf, 'co_liv', 'fk_commande', 'commande', 'fk_livraison', 'delivery'); - migrate_relationship_tables($db, $langs, $conf, 'co_pr', 'fk_propale', 'propal', 'fk_commande', 'commande'); + migrate_relationship_tables($db, $langs, $conf, 'co_pr', 'fk_propale', 'propal', 'fk_commande', 'commande'); - migrate_relationship_tables($db, $langs, $conf, 'fa_pr', 'fk_propal', 'propal', 'fk_facture', 'facture'); + migrate_relationship_tables($db, $langs, $conf, 'fa_pr', 'fk_propal', 'propal', 'fk_facture', 'facture'); - migrate_relationship_tables($db, $langs, $conf, 'co_fa', 'fk_commande', 'commande', 'fk_facture', 'facture'); + migrate_relationship_tables($db, $langs, $conf, 'co_fa', 'fk_commande', 'commande', 'fk_facture', 'facture'); - migrate_project_user_resp($db, $langs, $conf); + migrate_project_user_resp($db, $langs, $conf); - migrate_project_task_actors($db, $langs, $conf); - } + migrate_project_task_actors($db, $langs, $conf); + } - // Script for 2.9 - $afterversionarray = explode('.', '2.8.9'); - $beforeversionarray = explode('.', '2.9.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_project_task_time($db, $langs, $conf); + // Script for 2.9 + $afterversionarray = explode('.', '2.8.9'); + $beforeversionarray = explode('.', '2.9.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_project_task_time($db, $langs, $conf); - migrate_customerorder_shipping($db, $langs, $conf); + migrate_customerorder_shipping($db, $langs, $conf); - migrate_shipping_delivery($db, $langs, $conf); + migrate_shipping_delivery($db, $langs, $conf); - migrate_shipping_delivery2($db, $langs, $conf); - } + migrate_shipping_delivery2($db, $langs, $conf); + } - // Script for 3.0 - $afterversionarray = explode('.', '2.9.9'); - $beforeversionarray = explode('.', '3.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - // No particular code - } + // Script for 3.0 + $afterversionarray = explode('.', '2.9.9'); + $beforeversionarray = explode('.', '3.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + // No particular code + } - // Script for 3.1 - $afterversionarray = explode('.', '3.0.9'); - $beforeversionarray = explode('.', '3.1.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss'); + // Script for 3.1 + $afterversionarray = explode('.', '3.0.9'); + $beforeversionarray = explode('.', '3.1.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss'); - migrate_actioncomm_element($db, $langs, $conf); - } + migrate_actioncomm_element($db, $langs, $conf); + } - // Script for 3.2 - $afterversionarray = explode('.', '3.1.9'); - $beforeversionarray = explode('.', '3.2.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_price_contrat($db, $langs, $conf); + // Script for 3.2 + $afterversionarray = explode('.', '3.1.9'); + $beforeversionarray = explode('.', '3.2.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_price_contrat($db, $langs, $conf); - migrate_mode_reglement($db, $langs, $conf); + migrate_mode_reglement($db, $langs, $conf); - migrate_clean_association($db, $langs, $conf); - } + migrate_clean_association($db, $langs, $conf); + } - // Script for 3.3 - $afterversionarray = explode('.', '3.2.9'); - $beforeversionarray = explode('.', '3.3.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_categorie_association($db, $langs, $conf); - } + // Script for 3.3 + $afterversionarray = explode('.', '3.2.9'); + $beforeversionarray = explode('.', '3.3.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_categorie_association($db, $langs, $conf); + } // Script for 3.4 // No specific scripts - // Tasks to do always and only into last targeted version - $afterversionarray = explode('.', '3.6.9'); // target is after this - $beforeversionarray = explode('.', '3.7.9'); // target is before this - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_event_assignement($db, $langs, $conf); - } + // Tasks to do always and only into last targeted version + $afterversionarray = explode('.', '3.6.9'); // target is after this + $beforeversionarray = explode('.', '3.7.9'); // target is before this + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_event_assignement($db, $langs, $conf); + } - // Scripts for 3.9 - $afterversionarray = explode('.', '3.7.9'); - $beforeversionarray = explode('.', '3.8.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - // No particular code - } + // Scripts for 3.9 + $afterversionarray = explode('.', '3.7.9'); + $beforeversionarray = explode('.', '3.8.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + // No particular code + } - // Scripts for 4.0 - $afterversionarray = explode('.', '3.9.9'); - $beforeversionarray = explode('.', '4.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias'); - } + // Scripts for 4.0 + $afterversionarray = explode('.', '3.9.9'); + $beforeversionarray = explode('.', '4.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias'); + } - // Scripts for 5.0 - $afterversionarray = explode('.', '4.0.9'); - $beforeversionarray = explode('.', '5.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - // Migrate to add entity value into llx_societe_remise - migrate_remise_entity($db, $langs, $conf); + // Scripts for 5.0 + $afterversionarray = explode('.', '4.0.9'); + $beforeversionarray = explode('.', '5.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + // Migrate to add entity value into llx_societe_remise + migrate_remise_entity($db, $langs, $conf); - // Migrate to add entity value into llx_societe_remise_except - migrate_remise_except_entity($db, $langs, $conf); - } + // Migrate to add entity value into llx_societe_remise_except + migrate_remise_except_entity($db, $langs, $conf); + } - // Scripts for 6.0 - $afterversionarray = explode('.', '5.0.9'); - $beforeversionarray = explode('.', '6.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - if (!empty($conf->multicompany->enabled)) - { - global $multicompany_transverse_mode; + // Scripts for 6.0 + $afterversionarray = explode('.', '5.0.9'); + $beforeversionarray = explode('.', '6.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + if (!empty($conf->multicompany->enabled)) + { + global $multicompany_transverse_mode; - // Only if the transverse mode is not used - if (empty($multicompany_transverse_mode)) - { - // Migrate to add entity value into llx_user_rights - migrate_user_rights_entity($db, $langs, $conf); + // Only if the transverse mode is not used + if (empty($multicompany_transverse_mode)) + { + // Migrate to add entity value into llx_user_rights + migrate_user_rights_entity($db, $langs, $conf); - // Migrate to add entity value into llx_usergroup_rights - migrate_usergroup_rights_entity($db, $langs, $conf); - } - } - } + // Migrate to add entity value into llx_usergroup_rights + migrate_usergroup_rights_entity($db, $langs, $conf); + } + } + } - // Scripts for 7.0 - $afterversionarray = explode('.', '6.0.9'); - $beforeversionarray = explode('.', '7.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - // Migrate contact association - migrate_event_assignement_contact($db, $langs, $conf); + // Scripts for 7.0 + $afterversionarray = explode('.', '6.0.9'); + $beforeversionarray = explode('.', '7.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + // Migrate contact association + migrate_event_assignement_contact($db, $langs, $conf); - migrate_reset_blocked_log($db, $langs, $conf); - } + migrate_reset_blocked_log($db, $langs, $conf); + } - // Scripts for 8.0 - $afterversionarray = explode('.', '7.0.9'); - $beforeversionarray = explode('.', '8.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract'); - } + // Scripts for 8.0 + $afterversionarray = explode('.', '7.0.9'); + $beforeversionarray = explode('.', '8.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract'); + } - // Scripts for 9.0 - $afterversionarray = explode('.', '8.0.9'); - $beforeversionarray = explode('.', '9.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) - { - migrate_user_photospath(); - } + // Scripts for 9.0 + $afterversionarray = explode('.', '8.0.9'); + $beforeversionarray = explode('.', '9.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) + { + migrate_user_photospath(); + } - // Scripts for 11.0 - $afterversionarray = explode('.', '10.0.9'); - $beforeversionarray = explode('.', '11.0.9'); - if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { - migrate_users_socialnetworks(); - migrate_members_socialnetworks(); - migrate_contacts_socialnetworks(); - migrate_thirdparties_socialnetworks(); - } - } + // Scripts for 11.0 + $afterversionarray = explode('.', '10.0.9'); + $beforeversionarray = explode('.', '11.0.9'); + if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) { + migrate_users_socialnetworks(); + migrate_members_socialnetworks(); + migrate_contacts_socialnetworks(); + migrate_thirdparties_socialnetworks(); + } + } // Code executed only if migration is LAST ONE. Must always be done. if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3) @@ -497,86 +497,86 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ migrate_reload_menu($db, $langs, $conf); } - // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...' - // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line. - if (!$error && $enablemodules) - { - // Reload modules (this must be always done and only into last targeted version) - $listofmodules = array(); - $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules); - $tmplistofmodules = explode(',', $enablemodules); - foreach ($tmplistofmodules as $value) - { - $listofmodules[$value] = 'forceactivate'; - } - migrate_reload_modules($db, $langs, $conf, $listofmodules, 1); - } + // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...' + // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line. + if (!$error && $enablemodules) + { + // Reload modules (this must be always done and only into last targeted version) + $listofmodules = array(); + $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules); + $tmplistofmodules = explode(',', $enablemodules); + foreach ($tmplistofmodules as $value) + { + $listofmodules[$value] = 'forceactivate'; + } + migrate_reload_modules($db, $langs, $conf, $listofmodules, 1); + } - // Can call a dedicated external upgrade process - if (!$error) - { - $parameters = array('versionfrom'=>$versionfrom, 'versionto='.$versionto); - $object = new stdClass(); - $action = "upgrade"; - $reshook = $hookmanager->executeHooks('doUpgrade2', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - if ($hookmanager->resNbOfHooks > 0) - { - if ($reshook < 0) - { - print ''; - } else { - print ''; - } - } else { - //if (! empty($conf->modules)) - if (!empty($conf->modules_parts['hooks'])) // If there is at least one module with one hook, we show message to say nothing was done - { - print ''; - } - } - } + // Can call a dedicated external upgrade process + if (!$error) + { + $parameters = array('versionfrom'=>$versionfrom, 'versionto='.$versionto); + $object = new stdClass(); + $action = "upgrade"; + $reshook = $hookmanager->executeHooks('doUpgrade2', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + if ($hookmanager->resNbOfHooks > 0) + { + if ($reshook < 0) + { + print ''; + } else { + print ''; + } + } else { + //if (! empty($conf->modules)) + if (!empty($conf->modules_parts['hooks'])) // If there is at least one module with one hook, we show message to say nothing was done + { + print ''; + } + } + } - print '
'.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).''.$langs->trans('Error').'
'.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).''.$langs->trans('Error').'
'; - print ''.$langs->trans('UpgradeExternalModule').': '; - print $hookmanager->error; - print ""; - print '
'; - print ''.$langs->trans('UpgradeExternalModule').': OK'; - print ""; - print '
'; - print ''.$langs->trans('UpgradeExternalModule').': '.$langs->trans("None"); - print '
'; + print ''.$langs->trans('UpgradeExternalModule').': '; + print $hookmanager->error; + print ""; + print '
'; + print ''.$langs->trans('UpgradeExternalModule').': OK'; + print ""; + print '
'; + print ''.$langs->trans('UpgradeExternalModule').': '.$langs->trans("None"); + print '
'; + print ''; - $sql = 'UPDATE '.MAIN_DB_PREFIX."const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'"; - $db->query($sql, 1); + $sql = 'UPDATE '.MAIN_DB_PREFIX."const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'"; + $db->query($sql, 1); - // We always commit. - // Process is designed so we can run it several times whatever is situation. - $db->commit(); - $db->close(); + // We always commit. + // Process is designed so we can run it several times whatever is situation. + $db->commit(); + $db->close(); - // Copy directory medias - $srcroot = DOL_DOCUMENT_ROOT.'/install/medias'; - $destroot = DOL_DATA_ROOT.'/medias'; - dolCopyDir($srcroot, $destroot, 0, 0); + // Copy directory medias + $srcroot = DOL_DOCUMENT_ROOT.'/install/medias'; + $destroot = DOL_DATA_ROOT.'/medias'; + dolCopyDir($srcroot, $destroot, 0, 0); - // Actions for all versions (no database change but delete some files and directories) - migrate_delete_old_files($db, $langs, $conf); - migrate_delete_old_dir($db, $langs, $conf); - // Actions for all versions (no database change but create some directories) - dol_mkdir(DOL_DATA_ROOT.'/bank'); - // Actions for all versions (no database change but rename some directories) - migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits'); + // Actions for all versions (no database change but delete some files and directories) + migrate_delete_old_files($db, $langs, $conf); + migrate_delete_old_dir($db, $langs, $conf); + // Actions for all versions (no database change but create some directories) + dol_mkdir(DOL_DATA_ROOT.'/bank'); + // Actions for all versions (no database change but rename some directories) + migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits'); - print '

'.$langs->trans("MigrationFinished").'
'; + print '

'.$langs->trans("MigrationFinished").'
'; } else { - print '
'.$langs->trans('ErrorWrongParameters').'
'; - $error++; + print '
'.$langs->trans('ErrorWrongParameters').'
'; + $error++; } $ret = 0; @@ -603,78 +603,78 @@ if ($ret) exit($ret); */ function migrate_paiements($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); - $obj = $db->fetch_object($result); - if ($obj) - { - $sql = "SELECT p.rowid, p.fk_facture, p.amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.fk_facture > 0"; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); + $obj = $db->fetch_object($result); + if ($obj) + { + $sql = "SELECT p.rowid, p.fk_facture, p.amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; + $sql .= " WHERE p.fk_facture > 0"; - $resql = $db->query($sql); + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_paiements"); - if ($resql) - { - $i = 0; - $row = array(); - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_paiements"); + if ($resql) + { + $i = 0; + $row = array(); + $num = $db->num_rows($resql); - while ($i < $num) - { - $obj = $db->fetch_object($resql); - $row[$i][0] = $obj->rowid; - $row[$i][1] = $obj->fk_facture; - $row[$i][2] = $obj->amount; - $i++; - } - } else { - dol_print_error($db); - } + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $row[$i][0] = $obj->rowid; + $row[$i][1] = $obj->fk_facture; + $row[$i][2] = $obj->amount; + $i++; + } + } else { + dol_print_error($db); + } - if ($num) - { - print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."
\n"; - if ($db->begin()) - { - $res = 0; - $num = count($row); - for ($i = 0; $i < $num; $i++) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; - $sql .= " VALUES (".$row[$i][1].",".$row[$i][0].",".$row[$i][2].")"; + if ($num) + { + print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."
\n"; + if ($db->begin()) + { + $res = 0; + $num = count($row); + for ($i = 0; $i < $num; $i++) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; + $sql .= " VALUES (".$row[$i][1].",".$row[$i][0].",".$row[$i][2].")"; - $res += $db->query($sql); + $res += $db->query($sql); - $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".$row[$i][0]; + $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".$row[$i][0]; - $res += $db->query($sql); + $res += $db->query($sql); - print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."
\n"; - } - } + print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."
\n"; + } + } - if ($res == (2 * count($row))) - { - $db->commit(); - print $langs->trans('MigrationSuccessfullUpdate')."
"; - } else { - $db->rollback(); - print $langs->trans('MigrationUpdateFailed').'
'; - } - } else { - print $langs->trans('MigrationPaymentsNothingToUpdate')."
\n"; - } - } else { - print $langs->trans('MigrationPaymentsNothingToUpdate')."
\n"; - } + if ($res == (2 * count($row))) + { + $db->commit(); + print $langs->trans('MigrationSuccessfullUpdate')."
"; + } else { + $db->rollback(); + print $langs->trans('MigrationUpdateFailed').'
'; + } + } else { + print $langs->trans('MigrationPaymentsNothingToUpdate')."
\n"; + } + } else { + print $langs->trans('MigrationPaymentsNothingToUpdate')."
\n"; + } - print ''; + print ''; } /** @@ -689,109 +689,109 @@ function migrate_paiements($db, $langs, $conf) */ function migrate_paiements_orphelins_1($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); - $obj = $db->fetch_object($result); - if ($obj) - { - // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture - $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,"; - $sql .= " bu2.url_id as socid"; - $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')"; - $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid"; - $sql .= " AND b.rappro = 1"; - $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)"; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); + $obj = $db->fetch_object($result); + if ($obj) + { + // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture + $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,"; + $sql .= " bu2.url_id as socid"; + $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')"; + $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid"; + $sql .= " AND b.rappro = 1"; + $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)"; - $resql = $db->query($sql); + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1"); - $row = array(); - if ($resql) - { - $i = $j = 0; - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1"); + $row = array(); + if ($resql) + { + $i = $j = 0; + $num = $db->num_rows($resql); - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas - { - $row[$j]['paymentid'] = $obj->rowid; // paymentid - $row[$j]['pamount'] = $obj->pamount; - $row[$j]['fk_bank'] = $obj->fk_bank; - $row[$j]['bamount'] = $obj->bamount; - $row[$j]['socid'] = $obj->socid; - $row[$j]['datec'] = $obj->datec; - $j++; - } - $i++; - } - } else { - dol_print_error($db); - } + while ($i < $num) + { + $obj = $db->fetch_object($resql); + if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas + { + $row[$j]['paymentid'] = $obj->rowid; // paymentid + $row[$j]['pamount'] = $obj->pamount; + $row[$j]['fk_bank'] = $obj->fk_bank; + $row[$j]['bamount'] = $obj->bamount; + $row[$j]['socid'] = $obj->socid; + $row[$j]['datec'] = $obj->datec; + $j++; + } + $i++; + } + } else { + dol_print_error($db); + } - if (count($row)) - { - print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."
\n"; - $db->begin(); + if (count($row)) + { + print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."
\n"; + $db->begin(); - $res = 0; - $num = count($row); - for ($i = 0; $i < $num; $i++) - { - if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' bamount='.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'
'; + $res = 0; + $num = count($row); + for ($i = 0; $i < $num; $i++) + { + if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' bamount='.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'
'; - // On cherche facture sans lien paiement et du meme montant et pour meme societe. - $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; - $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount']; - $sql .= " AND pf.fk_facture IS NULL"; - $sql .= " ORDER BY f.fk_statut"; - //print $sql.'
'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - //print 'Nb of invoice found for this amount and company :'.$num.'
'; - if ($num >= 1) - { - $obj = $db->fetch_object($resql); - $facid = $obj->rowid; + // On cherche facture sans lien paiement et du meme montant et pour meme societe. + $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; + $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount']; + $sql .= " AND pf.fk_facture IS NULL"; + $sql .= " ORDER BY f.fk_statut"; + //print $sql.'
'; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + //print 'Nb of invoice found for this amount and company :'.$num.'
'; + if ($num >= 1) + { + $obj = $db->fetch_object($resql); + $facid = $obj->rowid; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; - $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; + $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")"; - $res += $db->query($sql); + $res += $db->query($sql); - print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."
\n"; - } - } else { - print 'ERROR'; - } - } + print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."
\n"; + } + } else { + print 'ERROR'; + } + } - if ($res > 0) - { - print $langs->trans('MigrationSuccessfullUpdate')."
"; - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } + if ($res > 0) + { + print $langs->trans('MigrationSuccessfullUpdate')."
"; + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } - $db->commit(); - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } + $db->commit(); + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } - print ''; + print ''; } /** @@ -806,124 +806,124 @@ function migrate_paiements_orphelins_1($db, $langs, $conf) */ function migrate_paiements_orphelins_2($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationPaymentsUpdate')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); - $obj = $db->fetch_object($result); - if ($obj) - { - // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture - $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,"; - $sql .= " bu2.url_id as socid"; - $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')"; - $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid"; - $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)"; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture"); + $obj = $db->fetch_object($result); + if ($obj) + { + // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture + $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,"; + $sql .= " bu2.url_id as socid"; + $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')"; + $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid"; + $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)"; - $resql = $db->query($sql); + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2"); - $row = array(); - if ($resql) - { - $i = $j = 0; - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2"); + $row = array(); + if ($resql) + { + $i = $j = 0; + $num = $db->num_rows($resql); - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas - { - $row[$j]['paymentid'] = $obj->rowid; // paymentid - $row[$j]['pamount'] = $obj->pamount; - $row[$j]['fk_bank'] = $obj->fk_bank; - $row[$j]['bamount'] = $obj->bamount; - $row[$j]['socid'] = $obj->socid; - $row[$j]['datec'] = $obj->datec; - $j++; - } - $i++; - } - } else { - dol_print_error($db); - } + while ($i < $num) + { + $obj = $db->fetch_object($resql); + if ($obj->pamount == $obj->bamount && $obj->socid) // Pour etre sur d'avoir bon cas + { + $row[$j]['paymentid'] = $obj->rowid; // paymentid + $row[$j]['pamount'] = $obj->pamount; + $row[$j]['fk_bank'] = $obj->fk_bank; + $row[$j]['bamount'] = $obj->bamount; + $row[$j]['socid'] = $obj->socid; + $row[$j]['datec'] = $obj->datec; + $j++; + } + $i++; + } + } else { + dol_print_error($db); + } - $nberr = 0; + $nberr = 0; - $num = count($row); - if ($num) - { - print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."
\n"; - $db->begin(); + $num = count($row); + if ($num) + { + print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."
\n"; + $db->begin(); - $res = 0; - for ($i = 0; $i < $num; $i++) - { - if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'
'; + $res = 0; + for ($i = 0; $i < $num; $i++) + { + if ($conf->global->MAIN_FEATURES_LEVEL == 2) print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' '.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'
'; - // On cherche facture sans lien paiement et du meme montant et pour meme societe. - $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; - $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount']; - $sql .= " AND pf.fk_facture IS NULL"; - $sql .= " ORDER BY f.fk_statut"; - //print $sql.'
'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - //print 'Nb of invoice found for this amount and company :'.$num.'
'; - if ($num >= 1) - { - $obj = $db->fetch_object($resql); - $facid = $obj->rowid; + // On cherche facture sans lien paiement et du meme montant et pour meme societe. + $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture"; + $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".$row[$i]['socid']." AND total_ttc = ".$row[$i]['pamount']; + $sql .= " AND pf.fk_facture IS NULL"; + $sql .= " ORDER BY f.fk_statut"; + //print $sql.'
'; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + //print 'Nb of invoice found for this amount and company :'.$num.'
'; + if ($num >= 1) + { + $obj = $db->fetch_object($resql); + $facid = $obj->rowid; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; - $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")"; - $res += $db->query($sql); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; + $sql .= " VALUES (".$facid.",".$row[$i]['paymentid'].",".$row[$i]['pamount'].")"; + $res += $db->query($sql); - print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."
\n"; - } - } else { - print 'ERROR'; - $nberr++; - } - } + print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."
\n"; + } + } else { + print 'ERROR'; + $nberr++; + } + } - if ($res > 0) - { - print $langs->trans('MigrationSuccessfullUpdate')."
"; - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } + if ($res > 0) + { + print $langs->trans('MigrationSuccessfullUpdate')."
"; + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } - $db->commit(); - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } + $db->commit(); + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } - // Delete obsolete fields fk_facture - $db->begin(); + // Delete obsolete fields fk_facture + $db->begin(); - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture"; - $db->query($sql); + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture"; + $db->query($sql); - if (!$nberr) - { - $db->commit(); - } else { - print 'ERROR'; - $db->rollback(); - } - } else { - print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; - } + if (!$nberr) + { + $db->commit(); + } else { + print 'ERROR'; + $db->rollback(); + } + } else { + print $langs->trans('MigrationPaymentsNothingUpdatable')."
\n"; + } - print ''; + print ''; } @@ -937,84 +937,84 @@ function migrate_paiements_orphelins_2($db, $langs, $conf) */ function migrate_contracts_det($db, $langs, $conf) { - print ''; + print ''; - $nberr = 0; + $nberr = 0; - print '
'; - print ''.$langs->trans('MigrationContractsUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationContractsUpdate')."
\n"; - $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,"; - $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p"; - $sql .= " ON c.fk_product = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd"; - $sql .= " ON c.rowid=cd.fk_contrat"; - $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL"; - $resql = $db->query($sql); + $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,"; + $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p"; + $sql .= " ON c.fk_product = p.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd"; + $sql .= " ON c.rowid=cd.fk_contrat"; + $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL"; + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_contracts_det"); - if ($resql) - { - $i = 0; - $row = array(); - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_contracts_det"); + if ($resql) + { + $i = 0; + $row = array(); + $num = $db->num_rows($resql); - if ($num) - { - print $langs->trans('MigrationContractsNumberToUpdate', $num)."
\n"; - $db->begin(); + if ($num) + { + print $langs->trans('MigrationContractsNumberToUpdate', $num)."
\n"; + $db->begin(); - while ($i < $num) - { - $obj = $db->fetch_object($resql); + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet ("; - $sql .= "fk_contrat, fk_product, statut, label, description,"; - $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,"; - $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)"; - $sql .= " VALUES ("; - $sql .= $obj->cref.", ".($obj->fk_product ? $obj->fk_product : 0).", "; - $sql .= "0, "; - $sql .= "'".$db->escape($obj->label)."', null, "; - $sql .= ($obj->date_contrat ? "'".$db->escape($obj->date_contrat)."'" : "null").", "; - $sql .= "null, "; - $sql .= "null, "; - $sql .= "'".$db->escape($obj->tva_tx)."' , 1, "; - $sql .= "'".$db->escape($obj->price)."', '".$db->escape($obj->price)."', ".$obj->fk_user_author.","; - $sql .= "null"; - $sql .= ")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet ("; + $sql .= "fk_contrat, fk_product, statut, label, description,"; + $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,"; + $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)"; + $sql .= " VALUES ("; + $sql .= $obj->cref.", ".($obj->fk_product ? $obj->fk_product : 0).", "; + $sql .= "0, "; + $sql .= "'".$db->escape($obj->label)."', null, "; + $sql .= ($obj->date_contrat ? "'".$db->escape($obj->date_contrat)."'" : "null").", "; + $sql .= "null, "; + $sql .= "null, "; + $sql .= "'".$db->escape($obj->tva_tx)."' , 1, "; + $sql .= "'".$db->escape($obj->price)."', '".$db->escape($obj->price)."', ".$obj->fk_user_author.","; + $sql .= "null"; + $sql .= ")"; - if ($db->query($sql)) - { - print $langs->trans('MigrationContractsLineCreation', $obj->cref)."
\n"; - } else { - dol_print_error($db); - $nberr++; - } + if ($db->query($sql)) + { + print $langs->trans('MigrationContractsLineCreation', $obj->cref)."
\n"; + } else { + dol_print_error($db); + $nberr++; + } - $i++; - } + $i++; + } - if (!$nberr) - { - // $db->rollback(); - $db->commit(); - print $langs->trans('MigrationSuccessfullUpdate')."
"; - } else { - $db->rollback(); - print $langs->trans('MigrationUpdateFailed').'
'; - } - } else { - print $langs->trans('MigrationContractsNothingToUpdate')."
\n"; - } - } else { - print $langs->trans('MigrationContractsFieldDontExist')."
\n"; - // dol_print_error($db); - } + if (!$nberr) + { + // $db->rollback(); + $db->commit(); + print $langs->trans('MigrationSuccessfullUpdate')."
"; + } else { + $db->rollback(); + print $langs->trans('MigrationUpdateFailed').'
'; + } + } else { + print $langs->trans('MigrationContractsNothingToUpdate')."
\n"; + } + } else { + print $langs->trans('MigrationContractsFieldDontExist')."
\n"; + // dol_print_error($db); + } - print ''; + print ''; } /** @@ -1027,73 +1027,73 @@ function migrate_contracts_det($db, $langs, $conf) */ function migrate_links_transfert($db, $langs, $conf) { - print ''; + print ''; - $nberr = 0; + $nberr = 0; - print '
'; - print ''.$langs->trans('MigrationBankTransfertsUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationBankTransfertsUpdate')."
\n"; - $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid"; - $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account"; - $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec"; - $sql .= " AND bu.fk_bank IS NULL"; - $resql = $db->query($sql); + $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid"; + $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account"; + $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec"; + $sql .= " AND bu.fk_bank IS NULL"; + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_links_transfert"); - if ($resql) - { - $i = 0; - $row = array(); - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_links_transfert"); + if ($resql) + { + $i = 0; + $row = array(); + $num = $db->num_rows($resql); - if ($num) - { - print $langs->trans('MigrationBankTransfertsToUpdate', $num)."
\n"; - $db->begin(); + if ($num) + { + print $langs->trans('MigrationBankTransfertsToUpdate', $num)."
\n"; + $db->begin(); - while ($i < $num) - { - $obj = $db->fetch_object($resql); + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url ("; - $sql .= "fk_bank, url_id, url, label, type"; - $sql .= ")"; - $sql .= " VALUES ("; - $sql .= $obj->barowid.",".$obj->bbrowid.", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'"; - $sql .= ")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url ("; + $sql .= "fk_bank, url_id, url, label, type"; + $sql .= ")"; + $sql .= " VALUES ("; + $sql .= $obj->barowid.",".$obj->bbrowid.", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'"; + $sql .= ")"; - print $sql.'
'; - dolibarr_install_syslog("migrate_links_transfert"); + print $sql.'
'; + dolibarr_install_syslog("migrate_links_transfert"); - if (!$db->query($sql)) - { - dol_print_error($db); - $nberr++; - } + if (!$db->query($sql)) + { + dol_print_error($db); + $nberr++; + } - $i++; - } + $i++; + } - if (!$nberr) - { - // $db->rollback(); - $db->commit(); - print $langs->trans('MigrationSuccessfullUpdate')."
"; - } else { - $db->rollback(); - print $langs->trans('MigrationUpdateFailed').'
'; - } - } else { - print $langs->trans('MigrationBankTransfertsNothingToUpdate')."
\n"; - } - } else { - dol_print_error($db); - } + if (!$nberr) + { + // $db->rollback(); + $db->commit(); + print $langs->trans('MigrationSuccessfullUpdate')."
"; + } else { + $db->rollback(); + print $langs->trans('MigrationUpdateFailed').'
'; + } + } else { + print $langs->trans('MigrationBankTransfertsNothingToUpdate')."
\n"; + } + } else { + dol_print_error($db); + } - print ''; + print ''; } /** @@ -1106,28 +1106,28 @@ function migrate_links_transfert($db, $langs, $conf) */ function migrate_contracts_date1($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationContractsEmptyDatesUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationContractsEmptyDatesUpdate')."
\n"; - $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null"; - dolibarr_install_syslog("upgrade2::migrate_contracts_date1"); - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - if ($db->affected_rows($resql) > 0) - print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."
\n"; - else print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."
\n"; + $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null"; + dolibarr_install_syslog("upgrade2::migrate_contracts_date1"); + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + if ($db->affected_rows($resql) > 0) + print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."
\n"; + else print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."
\n"; - $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null"; - dolibarr_install_syslog("upgrade2::migrate_contracts_date1"); - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - if ($db->affected_rows($resql) > 0) - print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."
\n"; - else print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."
\n"; + $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null"; + dolibarr_install_syslog("upgrade2::migrate_contracts_date1"); + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + if ($db->affected_rows($resql) > 0) + print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."
\n"; + else print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."
\n"; - print ''; + print ''; } /** @@ -1140,62 +1140,62 @@ function migrate_contracts_date1($db, $langs, $conf) */ function migrate_contracts_date2($db, $langs, $conf) { - print ''; + print ''; - $nberr = 0; + $nberr = 0; - print '
'; - print ''.$langs->trans('MigrationContractsInvalidDatesUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationContractsInvalidDatesUpdate')."
\n"; - $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin"; - $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,"; - $sql .= " ".MAIN_DB_PREFIX."contratdet as cd"; - $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL"; - $sql .= " GROUP BY c.rowid, c.date_contrat"; - $resql = $db->query($sql); + $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin"; + $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,"; + $sql .= " ".MAIN_DB_PREFIX."contratdet as cd"; + $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL"; + $sql .= " GROUP BY c.rowid, c.date_contrat"; + $resql = $db->query($sql); - dolibarr_install_syslog("upgrade2::migrate_contracts_date2"); - if ($resql) - { - $i = 0; - $row = array(); - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_contracts_date2"); + if ($resql) + { + $i = 0; + $row = array(); + $num = $db->num_rows($resql); - if ($num) - { - $nbcontratsmodifie = 0; - $db->begin(); + if ($num) + { + $nbcontratsmodifie = 0; + $db->begin(); - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj->date_contrat > $obj->datemin) - { - $datemin = $db->jdate($obj->datemin); + while ($i < $num) + { + $obj = $db->fetch_object($resql); + if ($obj->date_contrat > $obj->datemin) + { + $datemin = $db->jdate($obj->datemin); - print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."
\n"; - $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; - $sql .= " SET date_contrat='".$db->idate($datemin)."'"; - $sql .= " WHERE rowid=".$obj->cref; - $resql2 = $db->query($sql); - if (!$resql2) dol_print_error($db); + print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."
\n"; + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; + $sql .= " SET date_contrat='".$db->idate($datemin)."'"; + $sql .= " WHERE rowid=".$obj->cref; + $resql2 = $db->query($sql); + if (!$resql2) dol_print_error($db); - $nbcontratsmodifie++; - } - $i++; - } + $nbcontratsmodifie++; + } + $i++; + } - $db->commit(); + $db->commit(); - if ($nbcontratsmodifie) - print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."
\n"; - else print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."
\n"; - } - } else { - dol_print_error($db); - } + if ($nbcontratsmodifie) + print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."
\n"; + else print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."
\n"; + } + } else { + dol_print_error($db); + } - print ''; + print ''; } /** @@ -1208,20 +1208,20 @@ function migrate_contracts_date2($db, $langs, $conf) */ function migrate_contracts_date3($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."
\n"; + print '
'; + print ''.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."
\n"; - $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat"; - dolibarr_install_syslog("upgrade2::migrate_contracts_date3"); - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - if ($db->affected_rows($resql) > 0) - print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."
\n"; - else print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."
\n"; + $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat"; + dolibarr_install_syslog("upgrade2::migrate_contracts_date3"); + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + if ($db->affected_rows($resql) > 0) + print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."
\n"; + else print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."
\n"; - print ''; + print ''; } /** @@ -1234,51 +1234,51 @@ function migrate_contracts_date3($db, $langs, $conf) */ function migrate_contracts_open($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationReopeningContracts')."
\n"; + print '
'; + print ''.$langs->trans('MigrationReopeningContracts')."
\n"; - $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd"; - $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat"; - dolibarr_install_syslog("upgrade2::migrate_contracts_open"); - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - if ($db->affected_rows($resql) > 0) { - $i = 0; - $row = array(); - $num = $db->num_rows($resql); + $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd"; + $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat"; + dolibarr_install_syslog("upgrade2::migrate_contracts_open"); + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + if ($db->affected_rows($resql) > 0) { + $i = 0; + $row = array(); + $num = $db->num_rows($resql); - if ($num) - { - $nbcontratsmodifie = 0; - $db->begin(); + if ($num) + { + $nbcontratsmodifie = 0; + $db->begin(); - while ($i < $num) - { - $obj = $db->fetch_object($resql); + while ($i < $num) + { + $obj = $db->fetch_object($resql); - print $langs->trans('MigrationReopenThisContract', $obj->cref)."
\n"; - $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; - $sql .= " SET statut=1"; - $sql .= " WHERE rowid=".$obj->cref; - $resql2 = $db->query($sql); - if (!$resql2) dol_print_error($db); + print $langs->trans('MigrationReopenThisContract', $obj->cref)."
\n"; + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; + $sql .= " SET statut=1"; + $sql .= " WHERE rowid=".$obj->cref; + $resql2 = $db->query($sql); + if (!$resql2) dol_print_error($db); - $nbcontratsmodifie++; + $nbcontratsmodifie++; - $i++; - } + $i++; + } - $db->commit(); + $db->commit(); - if ($nbcontratsmodifie) - print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."
\n"; - else print $langs->trans('MigrationReopeningContractsNothingToUpdate')."
\n"; - } - } else print $langs->trans('MigrationReopeningContractsNothingToUpdate')."
\n"; + if ($nbcontratsmodifie) + print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."
\n"; + else print $langs->trans('MigrationReopeningContractsNothingToUpdate')."
\n"; + } + } else print $langs->trans('MigrationReopeningContractsNothingToUpdate')."
\n"; - print ''; + print ''; } /** @@ -1291,101 +1291,101 @@ function migrate_contracts_open($db, $langs, $conf) */ function migrate_paiementfourn_facturefourn($db, $langs, $conf) { - global $bc; + global $bc; - print ''; - print '
'; - print ''.$langs->trans('SuppliersInvoices')."
\n"; - print ''; + print ''; + print '
'; + print ''.$langs->trans('SuppliersInvoices')."
\n"; + print ''; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn"); - $obj = $db->fetch_object($result); - if ($obj) - { - $error = 0; - $nb = 0; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; + $nb = 0; - $select_sql = 'SELECT rowid, fk_facture_fourn, amount'; - $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn'; - $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL'; + $select_sql = 'SELECT rowid, fk_facture_fourn, amount'; + $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn'; + $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL'; - dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn"); - $select_resql = $db->query($select_sql); - if ($select_resql) - { - $select_num = $db->num_rows($select_resql); - $i = 0; - $var = true; + dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn"); + $select_resql = $db->query($select_sql); + if ($select_resql) + { + $select_num = $db->num_rows($select_resql); + $i = 0; + $var = true; - // Pour chaque paiement fournisseur, on insere une ligne dans paiementfourn_facturefourn - while (($i < $select_num) && (!$error)) - { - $var = !$var; - $select_obj = $db->fetch_object($select_resql); + // Pour chaque paiement fournisseur, on insere une ligne dans paiementfourn_facturefourn + while (($i < $select_num) && (!$error)) + { + $var = !$var; + $select_obj = $db->fetch_object($select_resql); - // Verifier si la ligne est deja dans la nouvelle table. On ne veut pas inserer de doublons. - $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn'; - $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn'; - $check_sql .= ' WHERE fk_paiementfourn = '.$select_obj->rowid.' AND fk_facturefourn = '.$select_obj->fk_facture_fourn; - $check_resql = $db->query($check_sql); - if ($check_resql) - { - $check_num = $db->num_rows($check_resql); - if ($check_num == 0) - { - $db->begin(); + // Verifier si la ligne est deja dans la nouvelle table. On ne veut pas inserer de doublons. + $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn'; + $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn'; + $check_sql .= ' WHERE fk_paiementfourn = '.$select_obj->rowid.' AND fk_facturefourn = '.$select_obj->fk_facture_fourn; + $check_resql = $db->query($check_sql); + if ($check_resql) + { + $check_num = $db->num_rows($check_resql); + if ($check_num == 0) + { + $db->begin(); - if ($nb == 0) - { - print ''.$langs->trans('SuppliersInvoices').''; - print 'fk_paiementfournfk_facturefourn'.$langs->trans('Amount').' '; - } + if ($nb == 0) + { + print ''.$langs->trans('SuppliersInvoices').''; + print 'fk_paiementfournfk_facturefourn'.$langs->trans('Amount').' '; + } - print ''; - print ''.$select_obj->rowid.''.$select_obj->fk_facture_fourn.''.$select_obj->amount.''; + print ''; + print ''.$select_obj->rowid.''.$select_obj->fk_facture_fourn.''.$select_obj->amount.''; - $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET '; - $insert_sql .= ' fk_paiementfourn = \''.$select_obj->rowid.'\','; - $insert_sql .= ' fk_facturefourn = \''.$select_obj->fk_facture_fourn.'\','; - $insert_sql .= ' amount = \''.$select_obj->amount.'\''; - $insert_resql = $db->query($insert_sql); + $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET '; + $insert_sql .= ' fk_paiementfourn = \''.$select_obj->rowid.'\','; + $insert_sql .= ' fk_facturefourn = \''.$select_obj->fk_facture_fourn.'\','; + $insert_sql .= ' amount = \''.$select_obj->amount.'\''; + $insert_resql = $db->query($insert_sql); - if ($insert_resql) - { - $nb++; - print ''.$langs->trans("OK").''; - } else { - print 'Error on insert'; - $error++; - } - print ''; - } - } else { - $error++; - } - $i++; - } - } else { - $error++; - } + if ($insert_resql) + { + $nb++; + print ''.$langs->trans("OK").''; + } else { + print 'Error on insert'; + $error++; + } + print ''; + } + } else { + $error++; + } + $i++; + } + } else { + $error++; + } - if (!$error) - { - if (!$nb) - { - print ''.$langs->trans("AlreadyDone").''; - } - $db->commit(); + if (!$error) + { + if (!$nb) + { + print ''.$langs->trans("AlreadyDone").''; + } + $db->commit(); - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn"; - $db->query($sql); - } else { - print ''.$langs->trans("Error").''; - $db->rollback(); - } - } else { - print ''.$langs->trans("AlreadyDone").''; - } + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn"; + $db->query($sql); + } else { + print ''.$langs->trans("Error").''; + $db->rollback(); + } + } else { + print ''.$langs->trans("AlreadyDone").''; + } } /** @@ -1398,105 +1398,105 @@ function migrate_paiementfourn_facturefourn($db, $langs, $conf) */ function migrate_price_facture($db, $langs, $conf) { - $err = 0; + $err = 0; - $tmpmysoc = new Societe($db); - $tmpmysoc->setMysoc($conf); + $tmpmysoc = new Societe($db); + $tmpmysoc->setMysoc($conf); - $db->begin(); + $db->begin(); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationInvoice')."
\n"; + print '
'; + print ''.$langs->trans('MigrationInvoice')."
\n"; - // List of invoice lines not up to date - $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,"; - $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f"; - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE fd.fk_facture = f.rowid"; - $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)"; - //print $sql; + // List of invoice lines not up to date + $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,"; + $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f"; + $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE fd.fk_facture = f.rowid"; + $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)"; + //print $sql; - dolibarr_install_syslog("upgrade2::migrate_price_facture"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + dolibarr_install_syslog("upgrade2::migrate_price_facture"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $rowid = $obj->rowid; - $qty = $obj->qty; - $pu = $obj->subprice; - $vatrate = $obj->vatrate; - $remise_percent = $obj->remise_percent; - $remise_percent_global = $obj->remise_percent_global; - $total_ttc_f = $obj->total_ttc_f; - $info_bits = $obj->info_bits; + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $vatrate = $obj->vatrate; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + $total_ttc_f = $obj->total_ttc_f; + $info_bits = $obj->info_bits; - // On met a jour les 3 nouveaux champs - $facligne = new FactureLigne($db); - $facligne->fetch($rowid); + // On met a jour les 3 nouveaux champs + $facligne = new FactureLigne($db); + $facligne->fetch($rowid); - $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc); - $total_ht = $result[0]; - $total_tva = $result[1]; - $total_ttc = $result[2]; + $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; - $facligne->total_ht = $total_ht; - $facligne->total_tva = $total_tva; - $facligne->total_ttc = $total_ttc; + $facligne->total_ht = $total_ht; + $facligne->total_tva = $total_tva; + $facligne->total_ttc = $total_ttc; - dolibarr_install_syslog("upgrade2: line ".$rowid.": facid=".$obj->facid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); - print ". "; - $facligne->update_total(); + dolibarr_install_syslog("upgrade2: line ".$rowid.": facid=".$obj->facid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); + print ". "; + $facligne->update_total(); - /* On touche a facture mere uniquement si total_ttc = 0 */ - if (!$total_ttc_f) - { - $facture = new Facture($db); - $facture->id = $obj->facid; + /* On touche a facture mere uniquement si total_ttc = 0 */ + if (!$total_ttc_f) + { + $facture = new Facture($db); + $facture->id = $obj->facid; - if ($facture->fetch($facture->id) >= 0) - { - if ($facture->update_price() > 0) - { - //print $facture->id; - } else { - print "Error id=".$facture->id; - $err++; - } - } else { - print "Error #3"; - $err++; - } - } - print " "; + if ($facture->fetch($facture->id) >= 0) + { + if ($facture->update_price() > 0) + { + //print $facture->id; + } else { + print "Error id=".$facture->id; + $err++; + } + } else { + print "Error #3"; + $err++; + } + } + print " "; - $i++; - } - } else { - print $langs->trans("AlreadyDone"); - } - $db->free($resql); + $i++; + } + } else { + print $langs->trans("AlreadyDone"); + } + $db->free($resql); - $db->commit(); - } else { - print "Error #1 ".$db->error(); - $err++; + $db->commit(); + } else { + print "Error #1 ".$db->error(); + $err++; - $db->rollback(); - } + $db->rollback(); + } - print '
'; + print '
'; - print ''; + print ''; } /** @@ -1512,59 +1512,59 @@ function migrate_price_propal($db, $langs, $conf) $tmpmysoc = new Societe($db); $tmpmysoc->setMysoc($conf); - $db->begin(); + $db->begin(); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationProposal')."
\n"; + print '
'; + print ''.$langs->trans('MigrationProposal')."
\n"; - // List of proposal lines not up to date - $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,"; - $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p"; - $sql .= " WHERE pd.fk_propal = p.rowid"; - $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)"; + // List of proposal lines not up to date + $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,"; + $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p"; + $sql .= " WHERE pd.fk_propal = p.rowid"; + $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)"; - dolibarr_install_syslog("upgrade2::migrate_price_propal"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + dolibarr_install_syslog("upgrade2::migrate_price_propal"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $rowid = $obj->rowid; - $qty = $obj->qty; - $pu = $obj->subprice; - $vatrate = $obj->vatrate; - $remise_percent = $obj->remise_percent; - $remise_percent_global = $obj->remise_percent_global; - $info_bits = $obj->info_bits; + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $vatrate = $obj->vatrate; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + $info_bits = $obj->info_bits; - // On met a jour les 3 nouveaux champs - $propalligne = new PropaleLigne($db); - $propalligne->fetch($rowid); + // On met a jour les 3 nouveaux champs + $propalligne = new PropaleLigne($db); + $propalligne->fetch($rowid); - $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc); - $total_ht = $result[0]; - $total_tva = $result[1]; - $total_ttc = $result[2]; + $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; - $propalligne->total_ht = $total_ht; - $propalligne->total_tva = $total_tva; - $propalligne->total_ttc = $total_ttc; + $propalligne->total_ht = $total_ht; + $propalligne->total_tva = $total_tva; + $propalligne->total_ttc = $total_ttc; - dolibarr_install_syslog("upgrade2: Line ".$rowid.": propalid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); - print ". "; - $propalligne->update_total(); + dolibarr_install_syslog("upgrade2: Line ".$rowid.": propalid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); + print ". "; + $propalligne->update_total(); - /* On touche pas a propal mere + /* On touche pas a propal mere $propal = new Propal($db); $propal->id=$obj->rowid; if ( $propal->fetch($propal->id) >= 0 ) @@ -1583,24 +1583,24 @@ function migrate_price_propal($db, $langs, $conf) print "Error #3"; } */ - $i++; - } - } else { - print $langs->trans("AlreadyDone"); - } + $i++; + } + } else { + print $langs->trans("AlreadyDone"); + } - $db->free($resql); + $db->free($resql); - $db->commit(); - } else { - print "Error #1 ".$db->error(); + $db->commit(); + } else { + print "Error #1 ".$db->error(); - $db->rollback(); - } + $db->rollback(); + } - print '
'; + print '
'; - print ''; + print ''; } /** @@ -1613,79 +1613,79 @@ function migrate_price_propal($db, $langs, $conf) */ function migrate_price_contrat($db, $langs, $conf) { - $db->begin(); + $db->begin(); $tmpmysoc = new Societe($db); $tmpmysoc->setMysoc($conf); - if (empty($tmpmysoc->country_id)) $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error. + if (empty($tmpmysoc->country_id)) $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error. - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationContract')."
\n"; + print '
'; + print ''.$langs->trans('MigrationContract')."
\n"; - // List of contract lines not up to date - $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; - $sql .= " c.rowid as contratid"; - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; - $sql .= " WHERE cd.fk_contrat = c.rowid"; - $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)"; + // List of contract lines not up to date + $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; + $sql .= " c.rowid as contratid"; + $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; + $sql .= " WHERE cd.fk_contrat = c.rowid"; + $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)"; - dolibarr_install_syslog("upgrade2::migrate_price_contrat"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + dolibarr_install_syslog("upgrade2::migrate_price_contrat"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $rowid = $obj->rowid; - $qty = $obj->qty; - $pu = $obj->subprice; - $vatrate = $obj->vatrate; - $remise_percent = $obj->remise_percent; - $info_bits = $obj->info_bits; + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $vatrate = $obj->vatrate; + $remise_percent = $obj->remise_percent; + $info_bits = $obj->info_bits; - // On met a jour les 3 nouveaux champs - $contratligne = new ContratLigne($db); - //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis - $contratligne->fetch($rowid); + // On met a jour les 3 nouveaux champs + $contratligne = new ContratLigne($db); + //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis + $contratligne->fetch($rowid); - $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc); - $total_ht = $result[0]; - $total_tva = $result[1]; - $total_ttc = $result[2]; + $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; - $contratligne->total_ht = $total_ht; - $contratligne->total_tva = $total_tva; - $contratligne->total_ttc = $total_ttc; + $contratligne->total_ht = $total_ht; + $contratligne->total_tva = $total_tva; + $contratligne->total_ttc = $total_ttc; - dolibarr_install_syslog("upgrade2: Line ".$rowid.": contratdetid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." -> ".$total_ht.", ".$total_tva." , ".$total_ttc); - print ". "; - $contratligne->update_total(); + dolibarr_install_syslog("upgrade2: Line ".$rowid.": contratdetid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." -> ".$total_ht.", ".$total_tva." , ".$total_ttc); + print ". "; + $contratligne->update_total(); - $i++; - } - } else { - print $langs->trans("AlreadyDone"); - } + $i++; + } + } else { + print $langs->trans("AlreadyDone"); + } - $db->free($resql); + $db->free($resql); - $db->commit(); - } else { - print "Error #1 ".$db->error(); + $db->commit(); + } else { + print "Error #1 ".$db->error(); - $db->rollback(); - } + $db->rollback(); + } - print '
'; + print '
'; - print ''; + print ''; } /** @@ -1698,61 +1698,61 @@ function migrate_price_contrat($db, $langs, $conf) */ function migrate_price_commande($db, $langs, $conf) { - $db->begin(); + $db->begin(); - $tmpmysoc = new Societe($db); - $tmpmysoc->setMysoc($conf); + $tmpmysoc = new Societe($db); + $tmpmysoc->setMysoc($conf); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationOrder')."
\n"; + print '
'; + print ''.$langs->trans('MigrationOrder')."
\n"; - // List of sales orders lines not up to date - $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; - $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c"; - $sql .= " WHERE cd.fk_commande = c.rowid"; - $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)"; + // List of sales orders lines not up to date + $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; + $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c"; + $sql .= " WHERE cd.fk_commande = c.rowid"; + $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)"; - dolibarr_install_syslog("upgrade2::migrate_price_commande"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + dolibarr_install_syslog("upgrade2::migrate_price_commande"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $rowid = $obj->rowid; - $qty = $obj->qty; - $pu = $obj->subprice; - $vatrate = $obj->vatrate; - $remise_percent = $obj->remise_percent; - $remise_percent_global = $obj->remise_percent_global; - $info_bits = $obj->info_bits; + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $vatrate = $obj->vatrate; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + $info_bits = $obj->info_bits; - // On met a jour les 3 nouveaux champs - $commandeligne = new OrderLine($db); - $commandeligne->fetch($rowid); + // On met a jour les 3 nouveaux champs + $commandeligne = new OrderLine($db); + $commandeligne->fetch($rowid); - $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc); - $total_ht = $result[0]; - $total_tva = $result[1]; - $total_ttc = $result[2]; + $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; - $commandeligne->total_ht = $total_ht; - $commandeligne->total_tva = $total_tva; - $commandeligne->total_ttc = $total_ttc; + $commandeligne->total_ht = $total_ht; + $commandeligne->total_tva = $total_tva; + $commandeligne->total_ttc = $total_ttc; - dolibarr_install_syslog("upgrade2: Line ".$rowid." : commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); - print ". "; - $commandeligne->update_total(); + dolibarr_install_syslog("upgrade2: Line ".$rowid." : commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); + print ". "; + $commandeligne->update_total(); - /* On touche pas a facture mere + /* On touche pas a facture mere $commande = new Commande($db); $commande->id = $obj->rowid; if ( $commande->fetch($commande->id) >= 0 ) @@ -1771,15 +1771,15 @@ function migrate_price_commande($db, $langs, $conf) print "Error #3"; } */ - $i++; - } - } else { - print $langs->trans("AlreadyDone"); - } + $i++; + } + } else { + print $langs->trans("AlreadyDone"); + } - $db->free($resql); + $db->free($resql); - /* + /* $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet"; $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0"; $resql=$db->query($sql); @@ -1789,16 +1789,16 @@ function migrate_price_commande($db, $langs, $conf) } */ - $db->commit(); - } else { - print "Error #1 ".$db->error(); + $db->commit(); + } else { + print "Error #1 ".$db->error(); - $db->rollback(); - } + $db->rollback(); + } - print '
'; + print '
'; - print ''; + print ''; } /** @@ -1811,61 +1811,61 @@ function migrate_price_commande($db, $langs, $conf) */ function migrate_price_commande_fournisseur($db, $langs, $conf) { - $db->begin(); + $db->begin(); - $tmpmysoc = new Societe($db); - $tmpmysoc->setMysoc($conf); + $tmpmysoc = new Societe($db); + $tmpmysoc->setMysoc($conf); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationSupplierOrder')."
\n"; + print '
'; + print ''.$langs->trans('MigrationSupplierOrder')."
\n"; - // List of purchase order lines not up to date - $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; - $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql .= " WHERE cd.fk_commande = c.rowid"; - $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)"; + // List of purchase order lines not up to date + $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,"; + $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c"; + $sql .= " WHERE cd.fk_commande = c.rowid"; + $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)"; - dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $rowid = $obj->rowid; - $qty = $obj->qty; - $pu = $obj->subprice; - $vatrate = $obj->vatrate; - $remise_percent = $obj->remise_percent; - $remise_percent_global = $obj->remise_percent_global; - $info_bits = $obj->info_bits; + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $vatrate = $obj->vatrate; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + $info_bits = $obj->info_bits; - // On met a jour les 3 nouveaux champs - $commandeligne = new CommandeFournisseurLigne($db); - $commandeligne->fetch($rowid); + // On met a jour les 3 nouveaux champs + $commandeligne = new CommandeFournisseurLigne($db); + $commandeligne->fetch($rowid); - $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpsoc); - $total_ht = $result[0]; - $total_tva = $result[1]; - $total_ttc = $result[2]; + $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpsoc); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; - $commandeligne->total_ht = $total_ht; - $commandeligne->total_tva = $total_tva; - $commandeligne->total_ttc = $total_ttc; + $commandeligne->total_ht = $total_ht; + $commandeligne->total_tva = $total_tva; + $commandeligne->total_ttc = $total_ttc; - dolibarr_install_syslog("upgrade2: Line ".$rowid.": commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); - print ". "; - $commandeligne->update_total(); + dolibarr_install_syslog("upgrade2: Line ".$rowid.": commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc); + print ". "; + $commandeligne->update_total(); - /* On touche pas a facture mere + /* On touche pas a facture mere $commande = new Commande($db); $commande->id = $obj->rowid; if ( $commande->fetch($commande->id) >= 0 ) @@ -1884,15 +1884,15 @@ function migrate_price_commande_fournisseur($db, $langs, $conf) print "Error #3"; } */ - $i++; - } - } else { - print $langs->trans("AlreadyDone"); - } + $i++; + } + } else { + print $langs->trans("AlreadyDone"); + } - $db->free($resql); + $db->free($resql); - /* + /* $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet"; $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0"; $resql=$db->query($sql); @@ -1902,16 +1902,16 @@ function migrate_price_commande_fournisseur($db, $langs, $conf) } */ - $db->commit(); - } else { - print "Error #1 ".$db->error(); + $db->commit(); + } else { + print "Error #1 ".$db->error(); - $db->rollback(); - } + $db->rollback(); + } - print '
'; + print '
'; - print ''; + print ''; } /** @@ -1924,51 +1924,51 @@ function migrate_price_commande_fournisseur($db, $langs, $conf) */ function migrate_modeles($db, $langs, $conf) { - //print '
'; - //print ''.$langs->trans('UpdateModelsTable')."
\n"; + //print '
'; + //print ''.$langs->trans('UpdateModelsTable')."
\n"; - dolibarr_install_syslog("upgrade2::migrate_modeles"); + dolibarr_install_syslog("upgrade2::migrate_modeles"); - if (!empty($conf->facture->enabled)) - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; - $modellist = ModelePDFFactures::liste_modeles($db); - if (count($modellist) == 0) - { - // Aucun model par defaut. - $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')"; - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - } - } + if (!empty($conf->facture->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; + $modellist = ModelePDFFactures::liste_modeles($db); + if (count($modellist) == 0) + { + // Aucun model par defaut. + $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')"; + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + } + } - if (!empty($conf->commande->enabled)) - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; - $modellist = ModelePDFCommandes::liste_modeles($db); - if (count($modellist) == 0) - { - // Aucun model par defaut. - $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')"; - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - } - } + if (!empty($conf->commande->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php'; + $modellist = ModelePDFCommandes::liste_modeles($db); + if (count($modellist) == 0) + { + // Aucun model par defaut. + $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')"; + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + } + } - if (!empty($conf->expedition->enabled)) - { - include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; - $modellist = ModelePDFExpedition::liste_modeles($db); - if (count($modellist) == 0) - { - // Aucun model par defaut. - $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')"; - $resql = $db->query($sql); - if (!$resql) dol_print_error($db); - } - } + if (!empty($conf->expedition->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; + $modellist = ModelePDFExpedition::liste_modeles($db); + if (count($modellist) == 0) + { + // Aucun model par defaut. + $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')"; + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + } + } - //print $langs->trans("AlreadyDone"); + //print $langs->trans("AlreadyDone"); } @@ -1982,65 +1982,65 @@ function migrate_modeles($db, $langs, $conf) */ function migrate_commande_expedition($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_commande_expedition"); + dolibarr_install_syslog("upgrade2::migrate_commande_expedition"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationShipmentOrderMatching')."
\n"; + print '
'; + print ''.$langs->trans('MigrationShipmentOrderMatching')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande"); - $obj = $db->fetch_object($result); - if ($obj) - { - $error = 0; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)"; - $sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")"; - $resql2 = $db->query($sql); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)"; + $sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")"; + $resql2 = $db->query($sql); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $db->commit(); - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande"; - print $langs->trans('FieldRenamed')."
\n"; - $db->query($sql); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - print ''; + if ($error == 0) + { + $db->commit(); + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande"; + print $langs->trans('FieldRenamed')."
\n"; + $db->query($sql); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; } /** @@ -2053,81 +2053,81 @@ function migrate_commande_expedition($db, $langs, $conf) */ function migrate_commande_livraison($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_commande_livraison"); + dolibarr_install_syslog("upgrade2::migrate_commande_livraison"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationDeliveryOrderMatching')."
\n"; + print '
'; + print ''.$langs->trans('MigrationDeliveryOrderMatching')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande"); - $obj = $db->fetch_object($result); - if ($obj) - { - $error = 0; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT l.rowid, l.fk_commande"; - $sql .= ", c.ref_client, c.date_livraison"; - $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; - $sql .= " WHERE c.rowid = l.fk_commande"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT l.rowid, l.fk_commande"; + $sql .= ", c.ref_client, c.date_livraison"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c"; + $sql .= " WHERE c.rowid = l.fk_commande"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)"; - $sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")"; - $resql2 = $db->query($sql); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)"; + $sql .= " VALUES (".$obj->rowid.",".$obj->fk_commande.")"; + $resql2 = $db->query($sql); - if ($resql2) - { - $delivery_date = $db->jdate($obj->date_livraison); + if ($resql2) + { + $delivery_date = $db->jdate($obj->date_livraison); - $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; - $sqlu .= " ref_client='".$db->escape($obj->ref_client)."'"; - $sqlu .= ", date_livraison='".$db->idate($delivery_date)."'"; - $sqlu .= " WHERE rowid = ".$obj->rowid; - $resql3 = $db->query($sqlu); - if (!$resql3) - { - $error++; - dol_print_error($db); - } - } else { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; + $sqlu .= " ref_client='".$db->escape($obj->ref_client)."'"; + $sqlu .= ", date_livraison='".$db->idate($delivery_date)."'"; + $sqlu .= " WHERE rowid = ".$obj->rowid; + $resql3 = $db->query($sqlu); + if (!$resql3) + { + $error++; + dol_print_error($db); + } + } else { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $db->commit(); - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande"; - print $langs->trans('FieldRenamed')."
\n"; - $db->query($sql); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - print ''; + if ($error == 0) + { + $db->commit(); + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande"; + print $langs->trans('FieldRenamed')."
\n"; + $db->query($sql); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; } /** @@ -2140,105 +2140,105 @@ function migrate_commande_livraison($db, $langs, $conf) */ function migrate_detail_livraison($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_detail_livraison"); + dolibarr_install_syslog("upgrade2::migrate_detail_livraison"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationDeliveryDetail')."
\n"; + print '
'; + print ''.$langs->trans('MigrationDeliveryDetail')."
\n"; - // This is done if field fk_commande_ligne exists. - // If not this means migration was already done. - $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne"); - $obj = $db->fetch_object($result); - if ($obj) - { - $error = 0; + // This is done if field fk_commande_ligne exists. + // If not this means migration was already done. + $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht"; - $sql .= ", ld.fk_livraison"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; - $sql .= " WHERE ld.fk_commande_ligne = cd.rowid"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht"; + $sql .= ", ld.fk_livraison"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld"; + $sql .= " WHERE ld.fk_commande_ligne = cd.rowid"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET"; - $sql .= " fk_product=".$obj->fk_product; - $sql .= ",description='".$db->escape($obj->description)."'"; - $sql .= ",subprice='".$db->escape($obj->subprice)."'"; - $sql .= ",total_ht='".$db->escape($obj->total_ht)."'"; - $sql .= " WHERE fk_commande_ligne = ".$obj->rowid; - $resql2 = $db->query($sql); + $sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET"; + $sql .= " fk_product=".$obj->fk_product; + $sql .= ",description='".$db->escape($obj->description)."'"; + $sql .= ",subprice='".$db->escape($obj->subprice)."'"; + $sql .= ",total_ht='".$db->escape($obj->total_ht)."'"; + $sql .= " WHERE fk_commande_ligne = ".$obj->rowid; + $resql2 = $db->query($sql); - if ($resql2) - { - $sql = "SELECT total_ht"; - $sql .= " FROM ".MAIN_DB_PREFIX."livraison"; - $sql .= " WHERE rowid = ".$obj->fk_livraison; - $resql3 = $db->query($sql); + if ($resql2) + { + $sql = "SELECT total_ht"; + $sql .= " FROM ".MAIN_DB_PREFIX."livraison"; + $sql .= " WHERE rowid = ".$obj->fk_livraison; + $resql3 = $db->query($sql); - if ($resql3) - { - $obju = $db->fetch_object($resql3); - $total_ht = $obju->total_ht + $obj->total_ht; + if ($resql3) + { + $obju = $db->fetch_object($resql3); + $total_ht = $obju->total_ht + $obj->total_ht; - $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; - $sqlu .= " total_ht='".$db->escape($total_ht)."'"; - $sqlu .= " WHERE rowid=".$obj->fk_livraison; - $resql4 = $db->query($sqlu); - if (!$resql4) - { - $error++; - dol_print_error($db); - } - } else { - $error++; - dol_print_error($db); - } - } else { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; + $sqlu .= " total_ht='".$db->escape($total_ht)."'"; + $sqlu .= " WHERE rowid=".$obj->fk_livraison; + $resql4 = $db->query($sqlu); + if (!$resql4) + { + $error++; + dol_print_error($db); + } + } else { + $error++; + dol_print_error($db); + } + } else { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $db->commit(); - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer"; - print $langs->trans('FieldRenamed')."
\n"; - $db->query($sql); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line"); - $obj = $db->fetch_object($result); - if (!$obj) - { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison"; - $db->query($sql); - } - print $langs->trans('AlreadyDone')."
\n"; - } - print ''; + if ($error == 0) + { + $db->commit(); + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer"; + print $langs->trans('FieldRenamed')."
\n"; + $db->query($sql); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line"); + $obj = $db->fetch_object($result); + if (!$obj) + { + $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison"; + $db->query($sql); + } + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; } /** @@ -2251,60 +2251,60 @@ function migrate_detail_livraison($db, $langs, $conf) */ function migrate_stocks($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_stocks"); + dolibarr_install_syslog("upgrade2::migrate_stocks"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationStockDetail')."
\n"; + print '
'; + print ''.$langs->trans('MigrationStockDetail')."
\n"; - $error = 0; + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT SUM(reel) as total, fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= " GROUP BY fk_product"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT SUM(reel) as total, fk_product"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; + $sql .= " GROUP BY fk_product"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; - $sql .= " stock = '".$db->escape($obj->total)."'"; - $sql .= " WHERE rowid=".$obj->fk_product; + $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; + $sql .= " stock = '".$db->escape($obj->total)."'"; + $sql .= " WHERE rowid=".$obj->fk_product; - $resql2 = $db->query($sql); - if ($resql2) - { - } else { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + $resql2 = $db->query($sql); + if ($resql2) + { + } else { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } - print ''; + print ''; } /** @@ -2318,66 +2318,66 @@ function migrate_stocks($db, $langs, $conf) */ function migrate_menus($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_menus"); + dolibarr_install_syslog("upgrade2::migrate_menus"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationMenusDetail')."
\n"; + print '
'; + print ''.$langs->trans('MigrationMenusDetail')."
\n"; - $error = 0; + $error = 0; - if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) - { - $db->begin(); + if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) + { + $db->begin(); - $sql = "SELECT m.rowid, mc.action"; - $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m"; - $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid"; - $sql .= " AND m.enabled = '1'"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + $sql = "SELECT m.rowid, mc.action"; + $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m"; + $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid"; + $sql .= " AND m.enabled = '1'"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; - $sql .= " enabled = '".$db->escape($obj->action)."'"; - $sql .= " WHERE rowid=".$obj->rowid; - $sql .= " AND enabled = '1'"; + $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; + $sql .= " enabled = '".$db->escape($obj->action)."'"; + $sql .= " WHERE rowid=".$obj->rowid; + $sql .= " AND enabled = '1'"; - $resql2 = $db->query($sql); - if ($resql2) - { - } else { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + $resql2 = $db->query($sql); + if ($resql2) + { + } else { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - print ''; + print ''; } /** @@ -2391,69 +2391,69 @@ function migrate_menus($db, $langs, $conf) */ function migrate_commande_deliveryaddress($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress"); + dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationDeliveryAddress')."
\n"; + print '
'; + print ''.$langs->trans('MigrationDeliveryAddress')."
\n"; - $error = 0; + $error = 0; - if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) - { - $db->begin(); + if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) + { + $db->begin(); - $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; - $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce"; - $sql .= " WHERE c.rowid = ce.fk_commande"; - $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0"; + $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition"; + $sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; + $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce"; + $sql .= " WHERE c.rowid = ce.fk_commande"; + $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; - $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'"; - $sql .= " WHERE rowid=".$obj->fk_expedition; + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; + $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'"; + $sql .= " WHERE rowid=".$obj->fk_expedition; - $resql2 = $db->query($sql); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $resql2 = $db->query($sql); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - print ''; + print ''; } /** @@ -2467,139 +2467,139 @@ function migrate_commande_deliveryaddress($db, $langs, $conf) */ function migrate_restore_missing_links($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_restore_missing_links"); + dolibarr_install_syslog("upgrade2::migrate_restore_missing_links"); - if (($db->type == 'mysql' || $db->type == 'mysqli')) - { - if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) - { - dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action"); - return 0; - } - } - print ''; + if (($db->type == 'mysql' || $db->type == 'mysqli')) + { + if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) + { + dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action"); + return 0; + } + } + print ''; - print '
'; - print ''.$langs->trans('MigrationFixData')." (1)
\n"; + print '
'; + print ''.$langs->trans('MigrationFixData')." (1)
\n"; - $error = 0; + $error = 0; - // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1. - $table1 = 'facturedet'; $field1 = 'fk_remise_except'; - $table2 = 'societe_remise_except'; $field2 = 'fk_facture_line'; + // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1. + $table1 = 'facturedet'; $field1 = 'fk_remise_except'; + $table2 = 'societe_remise_except'; $field2 = 'fk_facture_line'; - $db->begin(); + $db->begin(); - $sql = "SELECT t1.rowid, t1.".$field1." as field"; - $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1"; - $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN"; - $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2"; - $sql .= " WHERE t1.rowid = t2.".$field2.")"; + $sql = "SELECT t1.rowid, t1.".$field1." as field"; + $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1"; + $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN"; + $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2"; + $sql .= " WHERE t1.rowid = t2.".$field2.")"; - dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1"); - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1"); + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.
'; - $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET"; - $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'"; - $sql .= " WHERE rowid=".$obj->field; + print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.
'; + $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET"; + $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'"; + $sql .= " WHERE rowid=".$obj->field; - $resql2 = $db->query($sql); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - //print ". "; - $i++; - } - } else print $langs->trans('AlreadyDone')."
\n"; + $resql2 = $db->query($sql); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + //print ". "; + $i++; + } + } else print $langs->trans('AlreadyDone')."
\n"; - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } - print ''; + print ''; - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationFixData')." (2)
\n"; + print '
'; + print ''.$langs->trans('MigrationFixData')." (2)
\n"; - // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2. - $table2 = 'facturedet'; $field2 = 'fk_remise_except'; - $table1 = 'societe_remise_except'; $field1 = 'fk_facture_line'; + // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2. + $table2 = 'facturedet'; $field2 = 'fk_remise_except'; + $table1 = 'societe_remise_except'; $field1 = 'fk_facture_line'; - $db->begin(); + $db->begin(); - $sql = "SELECT t1.rowid, t1.".$field1." as field"; - $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1"; - $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN"; - $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2"; - $sql .= " WHERE t1.rowid = t2.".$field2.")"; + $sql = "SELECT t1.rowid, t1.".$field1." as field"; + $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1"; + $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN"; + $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2"; + $sql .= " WHERE t1.rowid = t2.".$field2.")"; - dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2"); - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2"); + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.
'; - $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET"; - $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'"; - $sql .= " WHERE rowid=".$obj->field; + print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.
'; + $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET"; + $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'"; + $sql .= " WHERE rowid=".$obj->field; - $resql2 = $db->query($sql); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - //print ". "; - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $resql2 = $db->query($sql); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + //print ". "; + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } - print ''; + print ''; } /** @@ -2612,83 +2612,83 @@ function migrate_restore_missing_links($db, $langs, $conf) */ function migrate_project_user_resp($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_project_user_resp"); + dolibarr_install_syslog("upgrade2::migrate_project_user_resp"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationProjectUserResp')."
\n"; + print '
'; + print ''.$langs->trans('MigrationProjectUserResp')."
\n"; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp"); - $obj = $db->fetch_object($result); - if ($obj) - { - $error = 0; + $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp"); + $obj = $db->fetch_object($result); + if ($obj) + { + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; - $sql2 .= "datecreate"; - $sql2 .= ", statut"; - $sql2 .= ", element_id"; - $sql2 .= ", fk_c_type_contact"; - $sql2 .= ", fk_socpeople"; - $sql2 .= ") VALUES ("; - $sql2 .= "'".$db->idate(dol_now())."'"; - $sql2 .= ", '4'"; - $sql2 .= ", ".$obj->rowid; - $sql2 .= ", '160'"; - $sql2 .= ", ".$obj->fk_user_resp; - $sql2 .= ")"; + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; + $sql2 .= "datecreate"; + $sql2 .= ", statut"; + $sql2 .= ", element_id"; + $sql2 .= ", fk_c_type_contact"; + $sql2 .= ", fk_socpeople"; + $sql2 .= ") VALUES ("; + $sql2 .= "'".$db->idate(dol_now())."'"; + $sql2 .= ", '4'"; + $sql2 .= ", ".$obj->rowid; + $sql2 .= ", '160'"; + $sql2 .= ", ".$obj->fk_user_resp; + $sql2 .= ")"; - if ($obj->fk_user_resp > 0) - { - $resql2 = $db->query($sql2); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - } - print ". "; + if ($obj->fk_user_resp > 0) + { + $resql2 = $db->query($sql2); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + } + print ". "; - $i++; - } - } + $i++; + } + } - if ($error == 0) - { - $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp"; - if ($db->query($sqlDrop)) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - print ''; + if ($error == 0) + { + $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp"; + if ($db->query($sqlDrop)) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; } /** @@ -2701,78 +2701,78 @@ function migrate_project_user_resp($db, $langs, $conf) */ function migrate_project_task_actors($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_project_task_actors"); + dolibarr_install_syslog("upgrade2::migrate_project_task_actors"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationProjectTaskActors')."
\n"; + print '
'; + print ''.$langs->trans('MigrationProjectTaskActors')."
\n"; - if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) - { - $error = 0; + if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) + { + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; - $sql2 .= "datecreate"; - $sql2 .= ", statut"; - $sql2 .= ", element_id"; - $sql2 .= ", fk_c_type_contact"; - $sql2 .= ", fk_socpeople"; - $sql2 .= ") VALUES ("; - $sql2 .= "'".$db->idate(dol_now())."'"; - $sql2 .= ", '4'"; - $sql2 .= ", ".$obj->fk_project_task; - $sql2 .= ", '180'"; - $sql2 .= ", ".$obj->fk_user; - $sql2 .= ")"; + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact ("; + $sql2 .= "datecreate"; + $sql2 .= ", statut"; + $sql2 .= ", element_id"; + $sql2 .= ", fk_c_type_contact"; + $sql2 .= ", fk_socpeople"; + $sql2 .= ") VALUES ("; + $sql2 .= "'".$db->idate(dol_now())."'"; + $sql2 .= ", '4'"; + $sql2 .= ", ".$obj->fk_project_task; + $sql2 .= ", '180'"; + $sql2 .= ", ".$obj->fk_user; + $sql2 .= ")"; - $resql2 = $db->query($sql2); + $resql2 = $db->query($sql2); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } - if ($error == 0) - { - $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors"; - if ($db->query($sqlDrop)) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - print ''; + if ($error == 0) + { + $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors"; + if ($db->query($sqlDrop)) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + print ''; } /** @@ -2790,80 +2790,80 @@ function migrate_project_task_actors($db, $langs, $conf) */ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."
\n"; + print '
'; + print ''.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."
\n"; - $error = 0; + $error = 0; - if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) - { - dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table); + if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) + { + dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table); - $db->begin(); + $db->begin(); - $sqlSelect = "SELECT ".$fk_source.", ".$fk_target; - $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table; + $sqlSelect = "SELECT ".$fk_source.", ".$fk_target; + $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table; - $resql = $db->query($sqlSelect); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; - $sqlInsert .= "fk_source"; - $sqlInsert .= ", sourcetype"; - $sqlInsert .= ", fk_target"; - $sqlInsert .= ", targettype"; - $sqlInsert .= ") VALUES ("; - $sqlInsert .= $obj->$fk_source; - $sqlInsert .= ", '".$db->escape($sourcetype)."'"; - $sqlInsert .= ", ".$obj->$fk_target; - $sqlInsert .= ", '".$db->escape($targettype)."'"; - $sqlInsert .= ")"; + $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; + $sqlInsert .= "fk_source"; + $sqlInsert .= ", sourcetype"; + $sqlInsert .= ", fk_target"; + $sqlInsert .= ", targettype"; + $sqlInsert .= ") VALUES ("; + $sqlInsert .= $obj->$fk_source; + $sqlInsert .= ", '".$db->escape($sourcetype)."'"; + $sqlInsert .= ", ".$obj->$fk_target; + $sqlInsert .= ", '".$db->escape($targettype)."'"; + $sqlInsert .= ")"; - $result = $db->query($sqlInsert); - if (!$result) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $result = $db->query($sqlInsert); + if (!$result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$table; - if ($db->query($sqlDrop)) - { - $db->commit(); - } else { - $db->rollback(); - } - } else { - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + if ($error == 0) + { + $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$table; + if ($db->query($sqlDrop)) + { + $db->commit(); + } else { + $db->rollback(); + } + } else { + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - print ''; + print ''; } /** @@ -2876,103 +2876,103 @@ function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $so */ function migrate_project_task_time($db, $langs, $conf) { - dolibarr_install_syslog("upgrade2::migrate_project_task_time"); + dolibarr_install_syslog("upgrade2::migrate_project_task_time"); - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationProjectTaskTime')."
\n"; + print '
'; + print ''.$langs->trans('MigrationProjectTaskTime')."
\n"; - $error = 0; + $error = 0; - $db->begin(); + $db->begin(); - $sql = "SELECT rowid, fk_task, task_duration"; - $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time"; - $resql = $db->query($sql); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $sql = "SELECT rowid, fk_task, task_duration"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - $totaltime = array(); - $oldtime = 0; + if ($num) + { + $totaltime = array(); + $oldtime = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); + while ($i < $num) + { + $obj = $db->fetch_object($resql); - if ($obj->task_duration > 0) - { - // convert to second - // only for int time and float time ex: 1,75 for 1h45 - list($hour, $min) = explode('.', $obj->task_duration); - $hour = $hour * 60 * 60; - $min = ($min / 100) * 60 * 60; - $newtime = $hour + $min; + if ($obj->task_duration > 0) + { + // convert to second + // only for int time and float time ex: 1,75 for 1h45 + list($hour, $min) = explode('.', $obj->task_duration); + $hour = $hour * 60 * 60; + $min = ($min / 100) * 60 * 60; + $newtime = $hour + $min; - $sql2 = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; - $sql2 .= " task_duration = ".$newtime; - $sql2 .= " WHERE rowid = ".$obj->rowid; + $sql2 = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; + $sql2 .= " task_duration = ".$newtime; + $sql2 .= " WHERE rowid = ".$obj->rowid; - $resql2 = $db->query($sql2); - if (!$resql2) - { - $error++; - dol_print_error($db); - } - print ". "; - $oldtime++; - if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $newtime; - else $totaltime[$obj->fk_task] = $newtime; - } else { - if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $obj->task_duration; - else $totaltime[$obj->fk_task] = $obj->task_duration; - } + $resql2 = $db->query($sql2); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $oldtime++; + if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $newtime; + else $totaltime[$obj->fk_task] = $newtime; + } else { + if (!empty($totaltime[$obj->fk_task])) $totaltime[$obj->fk_task] += $obj->task_duration; + else $totaltime[$obj->fk_task] = $obj->task_duration; + } - $i++; - } + $i++; + } - if ($error == 0) - { - if ($oldtime > 0) - { - foreach ($totaltime as $taskid => $total_duration) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET"; - $sql .= " duration_effective = ".$total_duration; - $sql .= " WHERE rowid = ".$taskid; + if ($error == 0) + { + if ($oldtime > 0) + { + foreach ($totaltime as $taskid => $total_duration) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET"; + $sql .= " duration_effective = ".$total_duration; + $sql .= " WHERE rowid = ".$taskid; - $resql = $db->query($sql); - if (!$resql) - { - $error++; - dol_print_error($db); - } - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - } else { - dol_print_error($db); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } - } else { - dol_print_error($db); - } + $resql = $db->query($sql); + if (!$resql) + { + $error++; + dol_print_error($db); + } + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + } else { + dol_print_error($db); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } + } else { + dol_print_error($db); + } - if ($error == 0) - { - $db->commit(); - } else { - $db->rollback(); - } + if ($error == 0) + { + $db->commit(); + } else { + $db->rollback(); + } - print ''; + print ''; } /** @@ -2985,85 +2985,85 @@ function migrate_project_task_time($db, $langs, $conf) */ function migrate_customerorder_shipping($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationCustomerOrderShipping')."
\n"; + print '
'; + print ''.$langs->trans('MigrationCustomerOrderShipping')."
\n"; - $error = 0; + $error = 0; - $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer"); - $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery"); - $obj1 = $db->fetch_object($result1); - $obj2 = $db->fetch_object($result2); - if (!$obj1 && !$obj2) - { - dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping"); + $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer"); + $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery"); + $obj1 = $db->fetch_object($result1); + $obj2 = $db->fetch_object($result2); + if (!$obj1 && !$obj2) + { + dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping"); - $db->begin(); + $db->begin(); - $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity"; - $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition"; + $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity"; + $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition"; - if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) - { - $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison"; - $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e"; - $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el"; - $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'"; - $sqlSelect .= " WHERE e.rowid = el.fk_target"; - $sqlSelect .= " AND el.targettype = 'shipping'"; + if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) + { + $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison"; + $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e"; + $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el"; + $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'"; + $sqlSelect .= " WHERE e.rowid = el.fk_target"; + $sqlSelect .= " AND el.targettype = 'shipping'"; - $resql = $db->query($sqlSelect); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; - $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'"; - $sqlUpdate .= ", date_delivery = '".$db->escape($obj->date_livraison ? $obj->date_livraison : 'null')."'"; - $sqlUpdate .= " WHERE rowid = ".$obj->shipping_id; + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; + $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'"; + $sqlUpdate .= ", date_delivery = '".$db->escape($obj->date_livraison ? $obj->date_livraison : 'null')."'"; + $sqlUpdate .= " WHERE rowid = ".$obj->shipping_id; - $result = $db->query($sqlUpdate); - if (!$result) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $result = $db->query($sqlUpdate); + if (!$result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + if ($error == 0) + { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - print ''; + print ''; } /** @@ -3076,95 +3076,95 @@ function migrate_customerorder_shipping($db, $langs, $conf) */ function migrate_shipping_delivery($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationShippingDelivery')."
\n"; + print '
'; + print ''.$langs->trans('MigrationShippingDelivery')."
\n"; - $error = 0; + $error = 0; - $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition"); - $obj = $db->fetch_object($result); - if ($obj) - { - dolibarr_install_syslog("upgrade2::migrate_shipping_delivery"); + $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition"); + $obj = $db->fetch_object($result); + if ($obj) + { + dolibarr_install_syslog("upgrade2::migrate_shipping_delivery"); - $db->begin(); + $db->begin(); - $sqlSelect = "SELECT rowid, fk_expedition"; - $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison"; - $sqlSelect .= " WHERE fk_expedition is not null"; + $sqlSelect = "SELECT rowid, fk_expedition"; + $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison"; + $sqlSelect .= " WHERE fk_expedition is not null"; - $resql = $db->query($sqlSelect); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; - $sqlInsert .= "fk_source"; - $sqlInsert .= ", sourcetype"; - $sqlInsert .= ", fk_target"; - $sqlInsert .= ", targettype"; - $sqlInsert .= ") VALUES ("; - $sqlInsert .= $obj->fk_expedition; - $sqlInsert .= ", 'shipping'"; - $sqlInsert .= ", ".$obj->rowid; - $sqlInsert .= ", 'delivery'"; - $sqlInsert .= ")"; + $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; + $sqlInsert .= "fk_source"; + $sqlInsert .= ", sourcetype"; + $sqlInsert .= ", fk_target"; + $sqlInsert .= ", targettype"; + $sqlInsert .= ") VALUES ("; + $sqlInsert .= $obj->fk_expedition; + $sqlInsert .= ", 'shipping'"; + $sqlInsert .= ", ".$obj->rowid; + $sqlInsert .= ", 'delivery'"; + $sqlInsert .= ")"; - $result = $db->query($sqlInsert); - if ($result) - { - $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL"; - $sqlUpdate .= " WHERE rowid = ".$obj->rowid; + $result = $db->query($sqlInsert); + if ($result) + { + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL"; + $sqlUpdate .= " WHERE rowid = ".$obj->rowid; - $result = $db->query($sqlUpdate); - if (!$result) - { - $error++; - dol_print_error($db); - } - print ". "; - } else { - $error++; - dol_print_error($db); - } - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $result = $db->query($sqlUpdate); + if (!$result) + { + $error++; + dol_print_error($db); + } + print ". "; + } else { + $error++; + dol_print_error($db); + } + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'"; - $db->query($sqlDelete); + if ($error == 0) + { + $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'"; + $db->query($sqlDelete); - $db->commit(); + $db->commit(); - // DDL commands must not be inside a transaction - $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition"; - $db->query($sqlDrop); - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + // DDL commands must not be inside a transaction + $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition"; + $db->query($sqlDrop); + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - print ''; + print ''; } /** @@ -3178,72 +3178,72 @@ function migrate_shipping_delivery($db, $langs, $conf) */ function migrate_shipping_delivery2($db, $langs, $conf) { - print ''; + print ''; - print '
'; - print ''.$langs->trans('MigrationShippingDelivery2')."
\n"; + print '
'; + print ''.$langs->trans('MigrationShippingDelivery2')."
\n"; - $error = 0; + $error = 0; - dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2"); + dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2"); - $db->begin(); + $db->begin(); - $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery"; - $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,"; - $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,"; - $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e"; - $sqlSelect .= " WHERE l.rowid = el.fk_target"; - $sqlSelect .= " AND el.targettype = 'delivery'"; - $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'"; - $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null - // Add condition to know if we never migrate this record - $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")"; - $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")"; + $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery"; + $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,"; + $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,"; + $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e"; + $sqlSelect .= " WHERE l.rowid = el.fk_target"; + $sqlSelect .= " AND el.targettype = 'delivery'"; + $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'"; + $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null + // Add condition to know if we never migrate this record + $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")"; + $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")"; - $resql = $db->query($sqlSelect); - if ($resql) - { - $i = 0; - $num = $db->num_rows($resql); + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); - if ($num) - { - while ($i < $num) - { - $obj = $db->fetch_object($resql); + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); - $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; - $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',"; - $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null'); - $sqlUpdate .= " WHERE rowid = ".$obj->delivery_id; + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET"; + $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',"; + $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null'); + $sqlUpdate .= " WHERE rowid = ".$obj->delivery_id; - $result = $db->query($sqlUpdate); - if (!$result) - { - $error++; - dol_print_error($db); - } - print ". "; - $i++; - } - } else { - print $langs->trans('AlreadyDone')."
\n"; - } + $result = $db->query($sqlUpdate); + if (!$result) + { + $error++; + dol_print_error($db); + } + print ". "; + $i++; + } + } else { + print $langs->trans('AlreadyDone')."
\n"; + } - if ($error == 0) - { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - } else { - dol_print_error($db); - $db->rollback(); - } + if ($error == 0) + { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + } else { + dol_print_error($db); + $db->rollback(); + } - print ''; + print ''; } /** @@ -3413,76 +3413,76 @@ function migrate_mode_reglement($db, $langs, $conf) */ function migrate_clean_association($db, $langs, $conf) { - $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association"); - if ($result) // result defined for version 3.2 or - - { - $obj = $db->fetch_object($result); - if ($obj) // It table categorie_association exists - { - $couples = array(); - $filles = array(); - $sql = "SELECT fk_categorie_mere, fk_categorie_fille"; - $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association"; - dolibarr_install_syslog("upgrade: search duplicate"); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - while ($obj = $db->fetch_object($resql)) - { - if (!isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent). - { - if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) - { - $filles[$obj->fk_categorie_fille] = 1; // Set record for this child - $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille); - } - } - } + $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association"); + if ($result) // result defined for version 3.2 or - + { + $obj = $db->fetch_object($result); + if ($obj) // It table categorie_association exists + { + $couples = array(); + $filles = array(); + $sql = "SELECT fk_categorie_mere, fk_categorie_fille"; + $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association"; + dolibarr_install_syslog("upgrade: search duplicate"); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + while ($obj = $db->fetch_object($resql)) + { + if (!isset($filles[$obj->fk_categorie_fille])) // Only one record as child (a child has only on parent). + { + if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) + { + $filles[$obj->fk_categorie_fille] = 1; // Set record for this child + $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere'=>$obj->fk_categorie_mere, 'fille'=>$obj->fk_categorie_fille); + } + } + } - dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples)); + dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples)); - // If there is duplicates couples or child with two parents - if (count($couples) > 0 && $num > count($couples)) - { - $error = 0; + // If there is duplicates couples or child with two parents + if (count($couples) > 0 && $num > count($couples)) + { + $error = 0; - $db->begin(); + $db->begin(); - // We delete all - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association"; - dolibarr_install_syslog("upgrade: delete association"); - $resqld = $db->query($sql); - if ($resqld) - { - // And we insert only each record once - foreach ($couples as $key => $val) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)"; - $sql .= " VALUES(".$val['mere'].", ".$val['fille'].")"; - dolibarr_install_syslog("upgrade: insert association"); - $resqli = $db->query($sql); - if (!$resqli) $error++; - } - } + // We delete all + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association"; + dolibarr_install_syslog("upgrade: delete association"); + $resqld = $db->query($sql); + if ($resqld) + { + // And we insert only each record once + foreach ($couples as $key => $val) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)"; + $sql .= " VALUES(".$val['mere'].", ".$val['fille'].")"; + dolibarr_install_syslog("upgrade: insert association"); + $resqli = $db->query($sql); + if (!$resqli) $error++; + } + } - if (!$error) - { - print ''.$langs->trans("MigrationCategorieAssociation").''; - print ''.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')'; - $db->commit(); - } else { - print ''.$langs->trans("MigrationCategorieAssociation").''; - print ''.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").''; - $db->rollback(); - } - } - } else { - print ''.$langs->trans("Error").''; - print '
'.$db->lasterror().'
'; - } - } - } + if (!$error) + { + print ''.$langs->trans("MigrationCategorieAssociation").''; + print ''.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')'; + $db->commit(); + } else { + print ''.$langs->trans("MigrationCategorieAssociation").''; + print ''.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").''; + $db->rollback(); + } + } + } else { + print ''.$langs->trans("Error").''; + print '
'.$db->lasterror().'
'; + } + } + } } @@ -4144,13 +4144,13 @@ function migrate_usergroup_rights_entity($db, $langs, $conf) */ function migrate_rename_directories($db, $langs, $conf, $oldname, $newname) { - dolibarr_install_syslog("upgrade2::migrate_rename_directories"); + dolibarr_install_syslog("upgrade2::migrate_rename_directories"); - if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) - { - dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname); - @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname); - } + if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) + { + dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname); + @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname); + } } @@ -4164,78 +4164,78 @@ function migrate_rename_directories($db, $langs, $conf, $oldname, $newname) */ function migrate_delete_old_files($db, $langs, $conf) { - $result = true; + $result = true; - dolibarr_install_syslog("upgrade2::migrate_delete_old_files"); + dolibarr_install_syslog("upgrade2::migrate_delete_old_files"); - // List of files to delete - $filetodeletearray = array( - '/core/triggers/interface_demo.class.php', - '/core/menus/barre_left/default.php', - '/core/menus/barre_top/default.php', - '/core/modules/modComptabiliteExpert.class.php', - '/core/modules/modCommercial.class.php', - '/core/modules/modProduit.class.php', - '/core/modules/modSkype.class.php', - '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php', - '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php', - '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php', - '/core/triggers/interface_modCommande_Ecotax.class.php', - '/core/triggers/interface_modCommande_fraisport.class.php', - '/core/triggers/interface_modPropale_PropalWorkflow.class.php', - '/core/menus/smartphone/iphone.lib.php', - '/core/menus/smartphone/iphone_backoffice.php', - '/core/menus/smartphone/iphone_frontoffice.php', - '/core/menus/standard/auguria_backoffice.php', - '/core/menus/standard/auguria_frontoffice.php', - '/core/menus/standard/eldy_backoffice.php', - '/core/menus/standard/eldy_frontoffice.php', - '/core/modules/mailings/contacts2.modules.php', - '/core/modules/mailings/contacts3.modules.php', - '/core/modules/mailings/contacts4.modules.php', - '/core/modules/mailings/framboise.modules.php', - '/core/modules/mailings/dolibarr_services_expired.modules.php', - '/core/modules/mailings/peche.modules.php', - '/core/modules/mailings/poire.modules.php', - '/core/modules/mailings/kiwi.modules.php', - '/core/modules/facture/pdf_crabe.modules.php', - '/core/modules/facture/pdf_oursin.modules.php', + // List of files to delete + $filetodeletearray = array( + '/core/triggers/interface_demo.class.php', + '/core/menus/barre_left/default.php', + '/core/menus/barre_top/default.php', + '/core/modules/modComptabiliteExpert.class.php', + '/core/modules/modCommercial.class.php', + '/core/modules/modProduit.class.php', + '/core/modules/modSkype.class.php', + '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php', + '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php', + '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php', + '/core/triggers/interface_modCommande_Ecotax.class.php', + '/core/triggers/interface_modCommande_fraisport.class.php', + '/core/triggers/interface_modPropale_PropalWorkflow.class.php', + '/core/menus/smartphone/iphone.lib.php', + '/core/menus/smartphone/iphone_backoffice.php', + '/core/menus/smartphone/iphone_frontoffice.php', + '/core/menus/standard/auguria_backoffice.php', + '/core/menus/standard/auguria_frontoffice.php', + '/core/menus/standard/eldy_backoffice.php', + '/core/menus/standard/eldy_frontoffice.php', + '/core/modules/mailings/contacts2.modules.php', + '/core/modules/mailings/contacts3.modules.php', + '/core/modules/mailings/contacts4.modules.php', + '/core/modules/mailings/framboise.modules.php', + '/core/modules/mailings/dolibarr_services_expired.modules.php', + '/core/modules/mailings/peche.modules.php', + '/core/modules/mailings/poire.modules.php', + '/core/modules/mailings/kiwi.modules.php', + '/core/modules/facture/pdf_crabe.modules.php', + '/core/modules/facture/pdf_oursin.modules.php', - '/api/class/api_generic.class.php', - '/categories/class/api_category.class.php', - '/categories/class/api_deprecated_category.class.php', - '/compta/facture/class/api_invoice.class.php', - '/commande/class/api_commande.class.php', - '/user/class/api_user.class.php', - '/product/class/api_product.class.php', - '/societe/class/api_contact.class.php', - '/societe/class/api_thirdparty.class.php', - '/support/online.php', - '/takepos/class/actions_takepos.class.php', + '/api/class/api_generic.class.php', + '/categories/class/api_category.class.php', + '/categories/class/api_deprecated_category.class.php', + '/compta/facture/class/api_invoice.class.php', + '/commande/class/api_commande.class.php', + '/user/class/api_user.class.php', + '/product/class/api_product.class.php', + '/societe/class/api_contact.class.php', + '/societe/class/api_thirdparty.class.php', + '/support/online.php', + '/takepos/class/actions_takepos.class.php', - '/install/mysql/tables/llx_c_ticketsup_category.key.sql', - '/install/mysql/tables/llx_c_ticketsup_category.sql', - '/install/mysql/tables/llx_c_ticketsup_severity.key.sql', - '/install/mysql/tables/llx_c_ticketsup_severity.sql', - '/install/mysql/tables/llx_c_ticketsup_type.key.sql', - '/install/mysql/tables/llx_c_ticketsup_type.sql' - ); + '/install/mysql/tables/llx_c_ticketsup_category.key.sql', + '/install/mysql/tables/llx_c_ticketsup_category.sql', + '/install/mysql/tables/llx_c_ticketsup_severity.key.sql', + '/install/mysql/tables/llx_c_ticketsup_severity.sql', + '/install/mysql/tables/llx_c_ticketsup_type.key.sql', + '/install/mysql/tables/llx_c_ticketsup_type.sql' + ); - foreach ($filetodeletearray as $filetodelete) { - //print ''DOL_DOCUMENT_ROOT.$filetodelete."
\n"; - $result = 1; - if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) { - $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0, null, true, false); - if (!$result) { - $langs->load("errors"); - print '
'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete); - print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'
'; - } else { - //print $langs->trans("FileWasRemoved", $filetodelete).'
'; - } - } - } - return $result; + foreach ($filetodeletearray as $filetodelete) { + //print ''DOL_DOCUMENT_ROOT.$filetodelete."
\n"; + $result = 1; + if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) { + $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0, null, true, false); + if (!$result) { + $langs->load("errors"); + print '
'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete); + print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'
'; + } else { + //print $langs->trans("FileWasRemoved", $filetodelete).'
'; + } + } + } + return $result; } /** @@ -4248,28 +4248,28 @@ function migrate_delete_old_files($db, $langs, $conf) */ function migrate_delete_old_dir($db, $langs, $conf) { - $result = true; + $result = true; - dolibarr_install_syslog("upgrade2::migrate_delete_old_dir"); + dolibarr_install_syslog("upgrade2::migrate_delete_old_dir"); - // List of files to delete - $filetodeletearray = array( - DOL_DOCUMENT_ROOT.'/core/modules/facture/terre', - DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure', - ); + // List of files to delete + $filetodeletearray = array( + DOL_DOCUMENT_ROOT.'/core/modules/facture/terre', + DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure', + ); - foreach ($filetodeletearray as $filetodelete) { - //print ''.$filetodelete."
\n"; - if (file_exists($filetodelete)) { - $result = dol_delete_dir_recursive($filetodelete); - } - if (!$result) { - $langs->load("errors"); - print '
'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete); - print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'
'; - } - } - return $result; + foreach ($filetodeletearray as $filetodelete) { + //print ''.$filetodelete."
\n"; + if (file_exists($filetodelete)) { + $result = dol_delete_dir_recursive($filetodelete); + } + if (!$result) { + $langs->load("errors"); + print '
'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete); + print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'
'; + } + } + return $result; } @@ -4530,35 +4530,35 @@ function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $fo */ function migrate_reload_menu($db, $langs, $conf) { - global $conf; - dolibarr_install_syslog("upgrade2::migrate_reload_menu"); + global $conf; + dolibarr_install_syslog("upgrade2::migrate_reload_menu"); - // Define list of menu handlers to initialize - $listofmenuhandler = array(); - if ($conf->global->MAIN_MENU_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE == 'auguria_menu' - || $conf->global->MAIN_MENUFRONT_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE == 'auguria_menu') - { - $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers - } + // Define list of menu handlers to initialize + $listofmenuhandler = array(); + if ($conf->global->MAIN_MENU_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE == 'auguria_menu' + || $conf->global->MAIN_MENUFRONT_STANDARD == 'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE == 'auguria_menu') + { + $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers + } - foreach ($listofmenuhandler as $key => $val) - { - print ''; + foreach ($listofmenuhandler as $key => $val) + { + print ''; - //print "x".$key; - print '
'; - print ''.$langs->trans('Upgrade').': '.$langs->trans('MenuHandler')." ".$key."
\n"; + //print "x".$key; + print '
'; + print ''.$langs->trans('Upgrade').': '.$langs->trans('MenuHandler')." ".$key."
\n"; - // Load sql ini_menu_handler.sql file - $dir = DOL_DOCUMENT_ROOT."/core/menus/"; - $file = 'init_menu_'.$key.'.sql'; - if (file_exists($dir.$file)) - { - $result = run_sql($dir.$file, 1, '', 1, $key); - } + // Load sql ini_menu_handler.sql file + $dir = DOL_DOCUMENT_ROOT."/core/menus/"; + $file = 'init_menu_'.$key.'.sql'; + if (file_exists($dir.$file)) + { + $result = run_sql($dir.$file, 1, '', 1, $key); + } - print ''; - } + print ''; + } } /** @@ -4608,44 +4608,44 @@ function migrate_user_photospath() if (dol_is_dir($origin)) { $handle = opendir($origin_osencoded); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if ($file == '.' || $file == '..') continue; + if (is_resource($handle)) + { + while (($file = readdir($handle)) !== false) + { + if ($file == '.' || $file == '..') continue; - if (dol_is_dir($origin.'/'.$file)) // it is a dir (like 'thumbs') - { - $thumbs = opendir($origin_osencoded.'/'.$file); - if (is_resource($thumbs)) - { - dol_mkdir($destin.'/'.$file); - while (($thumb = readdir($thumbs)) !== false) - { - if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) - { - if ($thumb == '.' || $thumb == '..') continue; + if (dol_is_dir($origin.'/'.$file)) // it is a dir (like 'thumbs') + { + $thumbs = opendir($origin_osencoded.'/'.$file); + if (is_resource($thumbs)) + { + dol_mkdir($destin.'/'.$file); + while (($thumb = readdir($thumbs)) !== false) + { + if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) + { + if ($thumb == '.' || $thumb == '..') continue; - //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'
'."\n"; - print '.'; - dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, 0, 0); - //var_dump('aaa');exit; - } - } + //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'
'."\n"; + print '.'; + dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, 0, 0); + //var_dump('aaa');exit; + } + } // dol_delete_dir($origin.'/'.$file); - } - } else // it is a file - { - if (!dol_is_file($destin.'/'.$file)) - { - //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'
'."\n"; - print '.'; - dol_copy($origin.'/'.$file, $destin.'/'.$file, 0, 0); - //var_dump('eee');exit; - } - } - } - } + } + } else // it is a file + { + if (!dol_is_file($destin.'/'.$file)) + { + //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'
'."\n"; + print '.'; + dol_copy($origin.'/'.$file, $destin.'/'.$file, 0, 0); + //var_dump('eee');exit; + } + } + } + } } } } @@ -4673,87 +4673,87 @@ and rowid in (...) */ function migrate_users_socialnetworks() { - global $db, $langs; - // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp - $error = 0; - $db->begin(); - print ''; - $sql = 'SELECT rowid, socialnetworks'; - $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE'; - $sql .= " skype IS NOT NULL OR skype <> ''"; - $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; - $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; - $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; - $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; - $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; - $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; - $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; - $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; - //print $sql; - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $arraysocialnetworks = array(); - if (!empty($obj->skype)) { - $arraysocialnetworks['skype'] = $obj->skype; - } - if (!empty($obj->twitter)) { - $arraysocialnetworks['twitter'] = $obj->twitter; - } - if (!empty($obj->facebook)) { - $arraysocialnetworks['facebook'] = $obj->facebook; - } - if (!empty($obj->linkedin)) { - $arraysocialnetworks['linkedin'] = $obj->linkedin; - } - if (!empty($obj->instagram)) { - $arraysocialnetworks['instagram'] = $obj->instagram; - } - if (!empty($obj->snapchat)) { - $arraysocialnetworks['snapchat'] = $obj->snapchat; - } - if (!empty($obj->googleplus)) { - $arraysocialnetworks['googleplus'] = $obj->googleplus; - } - if (!empty($obj->youtube)) { - $arraysocialnetworks['youtube'] = $obj->youtube; - } - if (!empty($obj->whatsapp)) { - $arraysocialnetworks['whatsapp'] = $obj->whatsapp; - } - if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { - $obj->socialnetworks = '[]'; - } - $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); - $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; - $sqlupd .= ', skype=null'; - $sqlupd .= ', twitter=null'; - $sqlupd .= ', facebook=null'; - $sqlupd .= ', linkedin=null'; - $sqlupd .= ', instagram=null'; - $sqlupd .= ', snapchat=null'; - $sqlupd .= ', googleplus=null'; - $sqlupd .= ', youtube=null'; - $sqlupd .= ', whatsapp=null'; - $sqlupd .= ' WHERE rowid='.$obj->rowid; - //print $sqlupd."
"; - $resqlupd = $db->query($sqlupd); - if (!$resqlupd) { - dol_print_error($db); - $error++; - } - } - } else { - $error++; - } - if (!$error) { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."
\n"; - print ''; + global $db, $langs; + // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp + $error = 0; + $db->begin(); + print ''; + $sql = 'SELECT rowid, socialnetworks'; + $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE'; + $sql .= " skype IS NOT NULL OR skype <> ''"; + $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; + $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; + $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; + $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; + $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; + $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; + $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; + $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; + //print $sql; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $arraysocialnetworks = array(); + if (!empty($obj->skype)) { + $arraysocialnetworks['skype'] = $obj->skype; + } + if (!empty($obj->twitter)) { + $arraysocialnetworks['twitter'] = $obj->twitter; + } + if (!empty($obj->facebook)) { + $arraysocialnetworks['facebook'] = $obj->facebook; + } + if (!empty($obj->linkedin)) { + $arraysocialnetworks['linkedin'] = $obj->linkedin; + } + if (!empty($obj->instagram)) { + $arraysocialnetworks['instagram'] = $obj->instagram; + } + if (!empty($obj->snapchat)) { + $arraysocialnetworks['snapchat'] = $obj->snapchat; + } + if (!empty($obj->googleplus)) { + $arraysocialnetworks['googleplus'] = $obj->googleplus; + } + if (!empty($obj->youtube)) { + $arraysocialnetworks['youtube'] = $obj->youtube; + } + if (!empty($obj->whatsapp)) { + $arraysocialnetworks['whatsapp'] = $obj->whatsapp; + } + if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { + $obj->socialnetworks = '[]'; + } + $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); + $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; + $sqlupd .= ', skype=null'; + $sqlupd .= ', twitter=null'; + $sqlupd .= ', facebook=null'; + $sqlupd .= ', linkedin=null'; + $sqlupd .= ', instagram=null'; + $sqlupd .= ', snapchat=null'; + $sqlupd .= ', googleplus=null'; + $sqlupd .= ', youtube=null'; + $sqlupd .= ', whatsapp=null'; + $sqlupd .= ' WHERE rowid='.$obj->rowid; + //print $sqlupd."
"; + $resqlupd = $db->query($sqlupd); + if (!$resqlupd) { + dol_print_error($db); + $error++; + } + } + } else { + $error++; + } + if (!$error) { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."
\n"; + print ''; } /** @@ -4763,88 +4763,88 @@ function migrate_users_socialnetworks() */ function migrate_members_socialnetworks() { - global $db, $langs; + global $db, $langs; - print ''; - $error = 0; - $db->begin(); - print ''; - $sql = 'SELECT rowid, socialnetworks'; - $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE '; - $sql .= " skype IS NOT NULL OR skype <> ''"; - $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; - $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; - $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; - $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; - $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; - $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; - $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; - $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; - //print $sql; - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $arraysocialnetworks = array(); - if (!empty($obj->skype)) { - $arraysocialnetworks['skype'] = $obj->skype; - } - if (!empty($obj->twitter)) { - $arraysocialnetworks['twitter'] = $obj->twitter; - } - if (!empty($obj->facebook)) { - $arraysocialnetworks['facebook'] = $obj->facebook; - } - if (!empty($obj->linkedin)) { - $arraysocialnetworks['linkedin'] = $obj->linkedin; - } - if (!empty($obj->instagram)) { - $arraysocialnetworks['instagram'] = $obj->instagram; - } - if (!empty($obj->snapchat)) { - $arraysocialnetworks['snapchat'] = $obj->snapchat; - } - if (!empty($obj->googleplus)) { - $arraysocialnetworks['googleplus'] = $obj->googleplus; - } - if (!empty($obj->youtube)) { - $arraysocialnetworks['youtube'] = $obj->youtube; - } - if (!empty($obj->whatsapp)) { - $arraysocialnetworks['whatsapp'] = $obj->whatsapp; - } - if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { - $obj->socialnetworks = '[]'; - } - $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); - $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; - $sqlupd .= ', skype=null'; - $sqlupd .= ', twitter=null'; - $sqlupd .= ', facebook=null'; - $sqlupd .= ', linkedin=null'; - $sqlupd .= ', instagram=null'; - $sqlupd .= ', snapchat=null'; - $sqlupd .= ', googleplus=null'; - $sqlupd .= ', youtube=null'; - $sqlupd .= ', whatsapp=null'; - $sqlupd .= ' WHERE rowid='.$obj->rowid; - //print $sqlupd."
"; - $resqlupd = $db->query($sqlupd); - if (!$resqlupd) { - dol_print_error($db); - $error++; - } - } - } else { - $error++; - } - if (!$error) { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."
\n"; - print ''; + print ''; + $error = 0; + $db->begin(); + print ''; + $sql = 'SELECT rowid, socialnetworks'; + $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE '; + $sql .= " skype IS NOT NULL OR skype <> ''"; + $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; + $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; + $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; + $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; + $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; + $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; + $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; + $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; + //print $sql; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $arraysocialnetworks = array(); + if (!empty($obj->skype)) { + $arraysocialnetworks['skype'] = $obj->skype; + } + if (!empty($obj->twitter)) { + $arraysocialnetworks['twitter'] = $obj->twitter; + } + if (!empty($obj->facebook)) { + $arraysocialnetworks['facebook'] = $obj->facebook; + } + if (!empty($obj->linkedin)) { + $arraysocialnetworks['linkedin'] = $obj->linkedin; + } + if (!empty($obj->instagram)) { + $arraysocialnetworks['instagram'] = $obj->instagram; + } + if (!empty($obj->snapchat)) { + $arraysocialnetworks['snapchat'] = $obj->snapchat; + } + if (!empty($obj->googleplus)) { + $arraysocialnetworks['googleplus'] = $obj->googleplus; + } + if (!empty($obj->youtube)) { + $arraysocialnetworks['youtube'] = $obj->youtube; + } + if (!empty($obj->whatsapp)) { + $arraysocialnetworks['whatsapp'] = $obj->whatsapp; + } + if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { + $obj->socialnetworks = '[]'; + } + $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); + $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; + $sqlupd .= ', skype=null'; + $sqlupd .= ', twitter=null'; + $sqlupd .= ', facebook=null'; + $sqlupd .= ', linkedin=null'; + $sqlupd .= ', instagram=null'; + $sqlupd .= ', snapchat=null'; + $sqlupd .= ', googleplus=null'; + $sqlupd .= ', youtube=null'; + $sqlupd .= ', whatsapp=null'; + $sqlupd .= ' WHERE rowid='.$obj->rowid; + //print $sqlupd."
"; + $resqlupd = $db->query($sqlupd); + if (!$resqlupd) { + dol_print_error($db); + $error++; + } + } + } else { + $error++; + } + if (!$error) { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."
\n"; + print ''; } /** @@ -4854,92 +4854,92 @@ function migrate_members_socialnetworks() */ function migrate_contacts_socialnetworks() { - global $db, $langs; - // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp - $error = 0; - $db->begin(); - print ''; - $sql = 'SELECT rowid, socialnetworks'; - $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE '; - $sql .= " jabberid IS NOT NULL OR jabberid <> ''"; - $sql .= " OR skype IS NOT NULL OR skype <> ''"; - $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; - $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; - $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; - $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; - $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; - $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; - $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; - $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; - //print $sql; - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $arraysocialnetworks = array(); - if (!empty($obj->jabberid)) { - $arraysocialnetworks['jabber'] = $obj->jabberid; - } - if (!empty($obj->skype)) { - $arraysocialnetworks['skype'] = $obj->skype; - } - if (!empty($obj->twitter)) { - $arraysocialnetworks['twitter'] = $obj->twitter; - } - if (!empty($obj->facebook)) { - $arraysocialnetworks['facebook'] = $obj->facebook; - } - if (!empty($obj->linkedin)) { - $arraysocialnetworks['linkedin'] = $obj->linkedin; - } - if (!empty($obj->instagram)) { - $arraysocialnetworks['instagram'] = $obj->instagram; - } - if (!empty($obj->snapchat)) { - $arraysocialnetworks['snapchat'] = $obj->snapchat; - } - if (!empty($obj->googleplus)) { - $arraysocialnetworks['googleplus'] = $obj->googleplus; - } - if (!empty($obj->youtube)) { - $arraysocialnetworks['youtube'] = $obj->youtube; - } - if (!empty($obj->whatsapp)) { - $arraysocialnetworks['whatsapp'] = $obj->whatsapp; - } - if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { - $obj->socialnetworks = '[]'; - } - $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); - $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; - $sqlupd .= ', jabberid=null'; - $sqlupd .= ', skype=null'; - $sqlupd .= ', twitter=null'; - $sqlupd .= ', facebook=null'; - $sqlupd .= ', linkedin=null'; - $sqlupd .= ', instagram=null'; - $sqlupd .= ', snapchat=null'; - $sqlupd .= ', googleplus=null'; - $sqlupd .= ', youtube=null'; - $sqlupd .= ', whatsapp=null'; - $sqlupd .= ' WHERE rowid='.$obj->rowid; - //print $sqlupd."
"; - $resqlupd = $db->query($sqlupd); - if (!$resqlupd) { - dol_print_error($db); - $error++; - } - } - } else { - $error++; - } - if (!$error) { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."
\n"; - print ''; + global $db, $langs; + // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp + $error = 0; + $db->begin(); + print ''; + $sql = 'SELECT rowid, socialnetworks'; + $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE '; + $sql .= " jabberid IS NOT NULL OR jabberid <> ''"; + $sql .= " OR skype IS NOT NULL OR skype <> ''"; + $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; + $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; + $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; + $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; + $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; + $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; + $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; + $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; + //print $sql; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $arraysocialnetworks = array(); + if (!empty($obj->jabberid)) { + $arraysocialnetworks['jabber'] = $obj->jabberid; + } + if (!empty($obj->skype)) { + $arraysocialnetworks['skype'] = $obj->skype; + } + if (!empty($obj->twitter)) { + $arraysocialnetworks['twitter'] = $obj->twitter; + } + if (!empty($obj->facebook)) { + $arraysocialnetworks['facebook'] = $obj->facebook; + } + if (!empty($obj->linkedin)) { + $arraysocialnetworks['linkedin'] = $obj->linkedin; + } + if (!empty($obj->instagram)) { + $arraysocialnetworks['instagram'] = $obj->instagram; + } + if (!empty($obj->snapchat)) { + $arraysocialnetworks['snapchat'] = $obj->snapchat; + } + if (!empty($obj->googleplus)) { + $arraysocialnetworks['googleplus'] = $obj->googleplus; + } + if (!empty($obj->youtube)) { + $arraysocialnetworks['youtube'] = $obj->youtube; + } + if (!empty($obj->whatsapp)) { + $arraysocialnetworks['whatsapp'] = $obj->whatsapp; + } + if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { + $obj->socialnetworks = '[]'; + } + $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); + $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; + $sqlupd .= ', jabberid=null'; + $sqlupd .= ', skype=null'; + $sqlupd .= ', twitter=null'; + $sqlupd .= ', facebook=null'; + $sqlupd .= ', linkedin=null'; + $sqlupd .= ', instagram=null'; + $sqlupd .= ', snapchat=null'; + $sqlupd .= ', googleplus=null'; + $sqlupd .= ', youtube=null'; + $sqlupd .= ', whatsapp=null'; + $sqlupd .= ' WHERE rowid='.$obj->rowid; + //print $sqlupd."
"; + $resqlupd = $db->query($sqlupd); + if (!$resqlupd) { + dol_print_error($db); + $error++; + } + } + } else { + $error++; + } + if (!$error) { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."
\n"; + print ''; } /** @@ -4949,85 +4949,85 @@ function migrate_contacts_socialnetworks() */ function migrate_thirdparties_socialnetworks() { - global $db, $langs; - // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp - $error = 0; - $db->begin(); - print ''; - $sql = 'SELECT rowid, socialnetworks'; - $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE '; - $sql .= " skype IS NOT NULL OR skype <> ''"; - $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; - $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; - $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; - $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; - $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; - $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; - $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; - $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; - //print $sql; - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - $arraysocialnetworks = array(); - if (!empty($obj->skype)) { - $arraysocialnetworks['skype'] = $obj->skype; - } - if (!empty($obj->twitter)) { - $arraysocialnetworks['twitter'] = $obj->twitter; - } - if (!empty($obj->facebook)) { - $arraysocialnetworks['facebook'] = $obj->facebook; - } - if (!empty($obj->linkedin)) { - $arraysocialnetworks['linkedin'] = $obj->linkedin; - } - if (!empty($obj->instagram)) { - $arraysocialnetworks['instagram'] = $obj->instagram; - } - if (!empty($obj->snapchat)) { - $arraysocialnetworks['snapchat'] = $obj->snapchat; - } - if (!empty($obj->googleplus)) { - $arraysocialnetworks['googleplus'] = $obj->googleplus; - } - if (!empty($obj->youtube)) { - $arraysocialnetworks['youtube'] = $obj->youtube; - } - if (!empty($obj->whatsapp)) { - $arraysocialnetworks['whatsapp'] = $obj->whatsapp; - } - if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { - $obj->socialnetworks = '[]'; - } - $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); - $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; - $sqlupd .= ', skype=null'; - $sqlupd .= ', twitter=null'; - $sqlupd .= ', facebook=null'; - $sqlupd .= ', linkedin=null'; - $sqlupd .= ', instagram=null'; - $sqlupd .= ', snapchat=null'; - $sqlupd .= ', googleplus=null'; - $sqlupd .= ', youtube=null'; - $sqlupd .= ', whatsapp=null'; - $sqlupd .= ' WHERE rowid='.$obj->rowid; - //print $sqlupd."
"; - $resqlupd = $db->query($sqlupd); - if (!$resqlupd) { - dol_print_error($db); - $error++; - } - } - } else { - $error++; - } - if (!$error) { - $db->commit(); - } else { - dol_print_error($db); - $db->rollback(); - } - print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."
\n"; - print ''; + global $db, $langs; + // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp + $error = 0; + $db->begin(); + print ''; + $sql = 'SELECT rowid, socialnetworks'; + $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE '; + $sql .= " skype IS NOT NULL OR skype <> ''"; + $sql .= " OR twitter IS NOT NULL OR twitter <> ''"; + $sql .= " OR facebook IS NOT NULL OR facebook <> ''"; + $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''"; + $sql .= " OR instagram IS NOT NULL OR instagram <> ''"; + $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''"; + $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''"; + $sql .= " OR youtube IS NOT NULL OR youtube <> ''"; + $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''"; + //print $sql; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $arraysocialnetworks = array(); + if (!empty($obj->skype)) { + $arraysocialnetworks['skype'] = $obj->skype; + } + if (!empty($obj->twitter)) { + $arraysocialnetworks['twitter'] = $obj->twitter; + } + if (!empty($obj->facebook)) { + $arraysocialnetworks['facebook'] = $obj->facebook; + } + if (!empty($obj->linkedin)) { + $arraysocialnetworks['linkedin'] = $obj->linkedin; + } + if (!empty($obj->instagram)) { + $arraysocialnetworks['instagram'] = $obj->instagram; + } + if (!empty($obj->snapchat)) { + $arraysocialnetworks['snapchat'] = $obj->snapchat; + } + if (!empty($obj->googleplus)) { + $arraysocialnetworks['googleplus'] = $obj->googleplus; + } + if (!empty($obj->youtube)) { + $arraysocialnetworks['youtube'] = $obj->youtube; + } + if (!empty($obj->whatsapp)) { + $arraysocialnetworks['whatsapp'] = $obj->whatsapp; + } + if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) { + $obj->socialnetworks = '[]'; + } + $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true)); + $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks, true))."'"; + $sqlupd .= ', skype=null'; + $sqlupd .= ', twitter=null'; + $sqlupd .= ', facebook=null'; + $sqlupd .= ', linkedin=null'; + $sqlupd .= ', instagram=null'; + $sqlupd .= ', snapchat=null'; + $sqlupd .= ', googleplus=null'; + $sqlupd .= ', youtube=null'; + $sqlupd .= ', whatsapp=null'; + $sqlupd .= ' WHERE rowid='.$obj->rowid; + //print $sqlupd."
"; + $resqlupd = $db->query($sqlupd); + if (!$resqlupd) { + dol_print_error($db); + $error++; + } + } + } else { + $error++; + } + if (!$error) { + $db->commit(); + } else { + dol_print_error($db); + $db->rollback(); + } + print ''.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."
\n"; + print ''; } diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 12eeb364cde..99a117562a1 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -52,8 +52,8 @@ if (!empty($conf->fournisseur->enabled)) { } if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.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'; } $langs->loadLangs(array("receptions", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'sendings')); @@ -122,7 +122,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if ($cancel) + if ($cancel) { $action = ''; $object->fetch($id); // show reception also after canceling modification @@ -133,8 +133,8 @@ if (empty($reshook)) // Reopen if ($action == 'reopen' && $user->rights->reception->creer) { - $object->fetch($id); - $result = $object->reOpen(); + $object->fetch($id); + $result = $object->reOpen(); } // Confirm back to draft status @@ -164,24 +164,24 @@ if (empty($reshook)) // Set incoterm if ($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')); } if ($action == 'setref_supplier') { - $result = $object->fetch($id); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } + $result = $object->fetch($id); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } - $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'editref_supplier'; - } else { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } + $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editref_supplier'; + } else { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } } if ($action == 'update_extras') @@ -338,76 +338,76 @@ if (empty($reshook)) } - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; - if (!$error) - { - $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception. + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + if (!$error) + { + $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception. - if ($ret <= 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - } else { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); - $error++; - } + if ($ret <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + } else { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); + $error++; + } - if (!$error) - { - $db->commit(); - header("Location: card.php?id=".$object->id); - exit; - } else { - $db->rollback(); - $_GET["commande_id"] = GETPOST('commande_id', 'int'); - $action = 'create'; - } + if (!$error) + { + $db->commit(); + header("Location: card.php?id=".$object->id); + exit; + } else { + $db->rollback(); + $_GET["commande_id"] = GETPOST('commande_id', 'int'); + $action = 'create'; + } } elseif ($action == 'confirm_valid' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))) + ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))) ) { - $object->fetch_thirdparty(); + $object->fetch_thirdparty(); - $result = $object->valid($user); + $result = $object->valid($user); - if ($result < 0) - { + if ($result < 0) + { $langs->load("errors"); - setEventMessages($langs->trans($object->error), null, 'errors'); - } else { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records + setEventMessages($langs->trans($object->error), null, 'errors'); + } else { + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->model_pdf; + $ret = $object->fetch($id); // Reload to get new records - $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) dol_print_error($db, $result); - } - } + $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) dol_print_error($db, $result); + } + } } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->reception->supprimer) { - $result = $object->delete($user); - if ($result > 0) - { - header("Location: ".DOL_URL_ROOT.'/reception/index.php'); - exit; - } else { + $result = $object->delete($user); + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT.'/reception/index.php'); + exit; + } else { setEventMessages($object->error, $object->errors, 'errors'); - } + } } // TODO add alternative status /*elseif ($action == 'reopen' && (! empty($user->rights->reception->creer) || ! empty($user->rights->reception->reception_advance->validate))) @@ -440,33 +440,33 @@ if (empty($reshook)) || $action == 'settrueDepth' || $action == 'setshipping_method_id') { - $error = 0; + $error = 0; - if ($action == 'settracking_number') $object->tracking_number = trim(GETPOST('tracking_number', 'alpha')); - if ($action == 'settracking_url') $object->tracking_url = trim(GETPOST('tracking_url', 'int')); - if ($action == 'settrueWeight') { - $object->trueWeight = trim(GETPOST('trueWeight', 'int')); + if ($action == 'settracking_number') $object->tracking_number = trim(GETPOST('tracking_number', 'alpha')); + if ($action == 'settracking_url') $object->tracking_url = trim(GETPOST('tracking_url', 'int')); + if ($action == 'settrueWeight') { + $object->trueWeight = trim(GETPOST('trueWeight', 'int')); $object->weight_units = GETPOST('weight_units', 'int'); - } - if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth', 'int')); - if ($action == 'settrueHeight') { - $object->trueHeight = trim(GETPOST('trueHeight', 'int')); + } + if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth', 'int')); + if ($action == 'settrueHeight') { + $object->trueHeight = trim(GETPOST('trueHeight', 'int')); $object->size_units = GETPOST('size_units', 'int'); } - if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth', 'int')); - if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int')); + if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth', 'int')); + if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int')); - if (!$error) - { - if ($object->update($user) >= 0) - { - header("Location: card.php?id=".$object->id); - exit; - } - setEventMessages($object->error, $object->errors, 'errors'); - } + if (!$error) + { + if ($object->update($user) >= 0) + { + header("Location: card.php?id=".$object->id); + exit; + } + setEventMessages($object->error, $object->errors, 'errors'); + } - $action = ""; + $action = ""; } // Build document @@ -475,22 +475,22 @@ if (empty($reshook)) // Save last template used to generate document if (GETPOST('model')) $object->setDocModel($user, GETPOST('model', 'alpha')); - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $reception->thirdparty->default_lang; - if (!empty($newlang)) - { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } + // Define output language + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $reception->thirdparty->default_lang; + if (!empty($newlang)) + { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { + if ($result <= 0) + { setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } + $action = ''; + } } // Delete file in doc form @@ -505,20 +505,20 @@ if (empty($reshook)) else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors'); } elseif ($action == 'classifybilled') { - $object->fetch($id); - $result = $object->set_billed(); - if ($result >= 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit(); - } + $object->fetch($id); + $result = $object->set_billed(); + if ($result >= 0) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit(); + } } elseif ($action == 'classifyclosed') { - $object->fetch($id); - $result = $object->setClosed(); - if ($result >= 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); - exit(); - } + $object->fetch($id); + $result = $object->setClosed(); + if ($result >= 0) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit(); + } } /* @@ -683,165 +683,165 @@ $warehousestatic = new Entrepot($db); if ($action == 'create2') { - print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert'); + print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert'); - print '
'.$langs->trans("ReceptionCreationIsDoneFromOrder"); - $action = ''; $id = ''; $ref = ''; + print '
'.$langs->trans("ReceptionCreationIsDoneFromOrder"); + $action = ''; $id = ''; $ref = ''; } // Mode creation. if ($action == 'create') { - $recept = new Reception($db); + $recept = new Reception($db); - print load_fiche_titre($langs->trans("CreateReception")); - if (!$origin) - { - setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors'); - } + print load_fiche_titre($langs->trans("CreateReception")); + if (!$origin) + { + setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors'); + } - if ($origin) - { + if ($origin) + { if ($origin == 'supplierorder')$classname = 'CommandeFournisseur'; - else $classname = ucfirst($origin); + else $classname = ucfirst($origin); - $object = new $classname($db); - if ($object->fetch($origin_id)) // This include the fetch_lines - { - $soc = new Societe($db); - $soc->fetch($object->socid); + $object = new $classname($db); + if ($object->fetch($origin_id)) // This include the fetch_lines + { + $soc = new Societe($db); + $soc->fetch($object->socid); - $author = new User($db); - $author->fetch($object->user_author_id); + $author = new User($db); + $author->fetch($object->user_author_id); - if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db); + if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (GETPOST('entrepot_id', 'int')) - { - print ''; - } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if (GETPOST('entrepot_id', 'int')) + { + print ''; + } - print dol_get_fiche_head(''); + print dol_get_fiche_head(''); - print ''; + print '
'; - // Ref - print ''; - print "\n"; + // Ref + print ''; + print "\n"; - // Ref client - print ''; - print ''; + // Ref client + print ''; + print ''; - // Tiers - print ''; - print ''; - print ''; + // Tiers + print ''; + print ''; + print ''; - // Project - if (!empty($conf->projet->enabled)) - { - $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0; - if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project; - if ($origin == 'project') $projectid = ($originid ? $originid : 0); + // Project + if (!empty($conf->projet->enabled)) + { + $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0; + if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project; + if ($origin == 'project') $projectid = ($originid ? $originid : 0); - $langs->load("projects"); - print ''; - print ''; - print ''; - } + $langs->load("projects"); + print ''; + print ''; + print ''; + } - // Date delivery planned - print ''; - print '\n"; - print ''; + // Date delivery planned + print ''; + print '\n"; + print ''; - // Note Public - print ''; - print '"; + // Note Public + print ''; + print '"; - // Note Private - if ($object->note_private && !$user->socid) - { - print ''; - print '"; - } + // Note Private + if ($object->note_private && !$user->socid) + { + print ''; + print '"; + } - // Weight - print ''; - // Dim - print ''; + // Weight + print ''; + // Dim + print ''; - // Delivery method - print ""; - print '\n"; + // Delivery method + print ""; + print '\n"; - // Tracking number - print ""; - print '\n"; + // Tracking number + print ""; + print '\n"; - // Other attributes - $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid'=>$socid); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; + // Other attributes + $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid'=>$socid); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; - // Here $object can be of an object Order - $extrafields->fetch_name_optionals_label($object->table_element); - if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) { + // Here $object can be of an object Order + $extrafields->fetch_name_optionals_label($object->table_element); + if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) { // copy from order if ($object->fetch_optionals() > 0) { $recept->array_options = array_merge($recept->array_options, $object->array_options); @@ -917,51 +917,51 @@ if ($action == 'create') } - print ''; - print '
'; + print '
'; - print '
'; - if ($origin == 'supplierorder' && !empty($conf->fournisseur->enabled)) - { - print $langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref; - } - if ($origin == 'propal' && !empty($conf->propal->enabled)) - { - print $langs->trans("RefProposal").''.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref; - } - print '
'; + if ($origin == 'supplierorder' && !empty($conf->fournisseur->enabled)) + { + print $langs->trans("RefOrder").''.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref; + } + if ($origin == 'propal' && !empty($conf->propal->enabled)) + { + print $langs->trans("RefProposal").''.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref; + } + print '
'; - if ($origin == 'supplier_order') print $langs->trans('SupplierOrder'); - else print $langs->trans('RefSupplier'); - print ''; - print ''; - print '
'; + if ($origin == 'supplier_order') print $langs->trans('SupplierOrder'); + else print $langs->trans('RefSupplier'); + print ''; + print ''; + print '
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans('Company').''.$soc->getNomUrl(1).'
'.$langs->trans("Project").''; - $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0); - print '   id).'">'.$langs->trans("AddProject").''; - print '
'.$langs->trans("Project").''; + $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0); + print '   id).'">'.$langs->trans("AddProject").''; + print '
'.$langs->trans("DateDeliveryPlanned").''; - //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed. - $date_delivery = ($date_delivery ? $date_delivery : $object->date_livraison); // $date_delivery comes from GETPOST - print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1); - print "
'.$langs->trans("DateDeliveryPlanned").''; + //print dol_print_date($object->date_livraison,"day"); // date_livraison come from order and will be stored into date_delivery planed. + $date_delivery = ($date_delivery ? $date_delivery : $object->date_livraison); // $date_delivery comes from GETPOST + print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1); + print "
'.$langs->trans("NotePublic").''; - $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print "
'.$langs->trans("NotePublic").''; + $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print "
'.$langs->trans("NotePrivate").''; - $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); - print $doleditor->Create(1); - print "
'.$langs->trans("NotePrivate").''; + $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); + print $doleditor->Create(1); + print "
'; - print $langs->trans("Weight"); - print ' '; - $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2); - $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); - print $form->textwithpicto($text, $htmltext); - print '
'; - print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth"); - print ' '; - print ' x '; - print ' x '; - print ' '; - $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2); - $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); - print $form->textwithpicto($text, $htmltext); - print '
'; + print $langs->trans("Weight"); + print ' '; + $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2); + $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); + print $form->textwithpicto($text, $htmltext); + print '
'; + print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth"); + print ' '; + print ' x '; + print ' x '; + print ' '; + $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2); + $htmltext = $langs->trans("KeepEmptyForAutoCalculation"); + print $form->textwithpicto($text, $htmltext); + print '
".$langs->trans("ReceptionMethod")."'; - $recept->fetch_delivery_methods(); - print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print "
".$langs->trans("ReceptionMethod")."'; + $recept->fetch_delivery_methods(); + print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + print "
".$langs->trans("TrackingNumber")."'; - print ''; - print "
".$langs->trans("TrackingNumber")."'; + print ''; + print "
'; + print '
'; - // Load receptions already done for same order - $object->loadReceptions(); + // Load receptions already done for same order + $object->loadReceptions(); - if ($numAsked) - { - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - if (!empty($conf->stock->enabled)) - { + print ''; + if (!empty($conf->stock->enabled)) + { print ''; - } + } if (!empty($conf->productbatch->enabled)) { print ''; @@ -972,13 +972,13 @@ if ($action == 'create') print ''; } } - print "\n"; - } + print "\n"; + } - $indiceAsked = 1; - while ($indiceAsked <= $numAsked) - { - $product = new Product($db); + $indiceAsked = 1; + while ($indiceAsked <= $numAsked) + { + $product = new Product($db); foreach ($object->lines as $supplierLine) { if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) { $line = $supplierLine; @@ -987,81 +987,81 @@ if ($action == 'create') } - // Show product and description - $type = $line->product_type ? $line->product_type : $line->fk_product_type; - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - if (!empty($line->date_start)) $type = 1; - if (!empty($line->date_end)) $type = 1; + // Show product and description + $type = $line->product_type ? $line->product_type : $line->fk_product_type; + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + if (!empty($line->date_start)) $type = 1; + if (!empty($line->date_end)) $type = 1; - print ''."\n"; - print ''."\n"; + print ''."\n"; + print ''."\n"; - // Product label - if ($line->fk_product > 0) // If predefined product - { - $product->fetch($line->fk_product); - $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch - //var_dump($product->stock_warehouse[1]); + // Product label + if ($line->fk_product > 0) // If predefined product + { + $product->fetch($line->fk_product); + $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch + //var_dump($product->stock_warehouse[1]); - print ''; - } else { - print "'; + } else { + print "\n"; - } + // Show range + print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end)); + print "\n"; + } - // Qty - print ''; - $qtyProdCom = $line->qty; + print ''; + print ''; + $qtyProdCom = $line->qty; - // Qty already received - print ''; + $quantityDelivered = $object->receptions[$line->id]; + print $quantityDelivered; + print ''; + print ''; if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) @@ -1070,13 +1070,13 @@ if ($action == 'create') } else { $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty']; } - $warehouse_id = $dispatchLines[$indiceAsked]['ent']; + $warehouse_id = $dispatchLines[$indiceAsked]['ent']; $warehouseObject = null; if (!empty($conf->stock->enabled)) // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection { - print ''; + print ''; $stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number $deliverableQty = $dispatchLines[$indiceAsked]['qty']; @@ -1085,8 +1085,8 @@ if ($action == 'create') print ''; @@ -1155,26 +1155,26 @@ if ($action == 'create') print $line->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), $indiceAsked); } - $indiceAsked++; - } + $indiceAsked++; + } - print "
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").''.$langs->trans("QtyToReceive"); + if ($numAsked) + { + print '
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyReceived").''.$langs->trans("QtyToReceive"); if (empty($conf->productbatch->enabled)) { - print '
('.$langs->trans("Fill").''; - print ' / '.$langs->trans("Reset").')'; + print '
('.$langs->trans("Fill").''; + print ' / '.$langs->trans("Reset").')'; } - print '
'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')'.$langs->trans("batch_number").''.$langs->trans("SellByDate").'
'; - print ''; // ancre pour retourner sur la ligne + print ''; + print ''; // ancre pour retourner sur la ligne - // Show product and description - $product_static->type = $line->fk_product_type; - $product_static->id = $line->fk_product; - $product_static->ref = $line->ref; - $product_static->status_batch = $line->product_tobatch; + // Show product and description + $product_static->type = $line->fk_product_type; + $product_static->id = $line->fk_product; + $product_static->ref = $line->ref; + $product_static->status_batch = $line->product_tobatch; - $text = $product_static->getNomUrl(1); - $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); - $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->desc)); - print $form->textwithtooltip($text, $description, 3, '', '', $i); + $text = $product_static->getNomUrl(1); + $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); + $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->desc)); + print $form->textwithtooltip($text, $description, 3, '', '', $i); - // Show range - print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end)); + // Show range + print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end)); - // Add description in form - if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) - { - print ($line->desc && $line->desc != $line->product_label) ? '
'.dol_htmlentitiesbr($line->desc) : ''; - } + // Add description in form + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) + { + print ($line->desc && $line->desc != $line->product_label) ? '
'.dol_htmlentitiesbr($line->desc) : ''; + } - print '
"; - if ($type == 1) $text = img_object($langs->trans('Service'), 'service'); - else $text = img_object($langs->trans('Product'), 'product'); + print '"; + if ($type == 1) $text = img_object($langs->trans('Service'), 'service'); + else $text = img_object($langs->trans('Product'), 'product'); - if (!empty($line->label)) { - $text .= ' '.$line->label.''; - print $form->textwithtooltip($text, $line->desc, 3, '', '', $i); - } else { - print $text.' '.nl2br($line->desc); - } + if (!empty($line->label)) { + $text .= ' '.$line->label.''; + print $form->textwithtooltip($text, $line->desc, 3, '', '', $i); + } else { + print $text.' '.nl2br($line->desc); + } - // Show range - print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end)); - print "'.$line->qty; + // Qty + print ''.$line->qty; print 'id.'\' />'; print ''; - print ''; - print ''; + // Qty already received + print ''; - $quantityDelivered = $object->receptions[$line->id]; - print $quantityDelivered; - print ''; - print ''; if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { - if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty = GETPOST('qtyl'.$indiceAsked, 'int'); - print ''; + if (GETPOST('qtyl'.$indiceAsked, 'int')) $defaultqty = GETPOST('qtyl'.$indiceAsked, 'int'); + print ''; print ''; } else print $langs->trans("NA"); print '
"; + print ""; - print '
'; + print '
'; - print '
'; - print ''; - print '  '; - print ''; // Cancel for create does not post form if we don't know the backtopage - print '
'; + print '
'; + print ''; + print '  '; + print ''; // Cancel for create does not post form if we don't know the backtopage + print '
'; - print ''; + print ''; - print '
'; - } else { - dol_print_error($db); - } - } + print '
'; + } else { + dol_print_error($db); + } + } } elseif ($id || $ref) /* *************************************************************************** */ /* */ @@ -1245,9 +1245,9 @@ if ($action == 'create') if (!$formconfirm) { $parameters = array('formConfirm' => $formconfirm); - $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; + elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; } // Print form confirm @@ -1263,18 +1263,18 @@ if ($action == 'create') if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { - $objectsrc = new Commande($db); - $objectsrc->fetch($object->$typeobject->id); + $objectsrc = new Commande($db); + $objectsrc->fetch($object->$typeobject->id); } if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { - $objectsrc = new Propal($db); - $objectsrc->fetch($object->$typeobject->id); + $objectsrc = new Propal($db); + $objectsrc->fetch($object->$typeobject->id); } if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && !empty($conf->fournisseur->enabled)) { - $objectsrc = new CommandeFournisseur($db); - $objectsrc->fetch($object->$typeobject->id); + $objectsrc = new CommandeFournisseur($db); + $objectsrc->fetch($object->$typeobject->id); } // Reception card $linkback = ''.$langs->trans("BackToList").''; @@ -1285,53 +1285,53 @@ if ($action == 'create') $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->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 (0) { // Do not change on reception - 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 { - // We don't have project on reception, so we will use the project or source object instead - // TODO Add project on reception - $morehtmlref .= ' : '; - if (!empty($objectsrc->fk_project)) { - $proj = new Project($db); - $proj->fetch($objectsrc->fk_project); - $morehtmlref .= ''; - $morehtmlref .= $proj->ref; - $morehtmlref .= ''; - } else { - $morehtmlref .= ''; - } - } - } + $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + // Project + if (!empty($conf->projet->enabled)) + { + $langs->load("projects"); + $morehtmlref .= '
'.$langs->trans('Project').' '; + if (0) { // Do not change on reception + 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 { + // We don't have project on reception, so we will use the project or source object instead + // TODO Add project on reception + $morehtmlref .= ' : '; + if (!empty($objectsrc->fk_project)) { + $proj = new Project($db); + $proj->fetch($objectsrc->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; + } + } + } $morehtmlref .= '
'; $object->picto = 'sending'; - 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 ''; + print '
'; // Linked documents if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) @@ -1411,7 +1411,7 @@ if ($action == 'create') print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : ''; } - // Calculated + // Calculated if ($totalWeight > 0) { if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': '; @@ -1461,15 +1461,15 @@ if ($action == 'create') $volumeUnit = 0; if ($object->trueWidth && $object->trueHeight && $object->trueDepth) { - $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); - $volumeUnit = $object->size_units * 3; + $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); + $volumeUnit = $object->size_units * 3; } // If reception volume not defined we use sum of products if ($calculatedVolume > 0) { if ($volumeUnit < 50) { - print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "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 showDimensionInBestUnit($calculatedVolume, $volumeUnit, "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'); } else print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit); } if ($totalVolume > 0) @@ -1536,21 +1536,21 @@ if ($action == 'create') if (!empty($conf->incoterm->enabled)) { print ''; - print ''; + print ''; + print ''; } print "
'; - print '
'; - print $langs->trans('IncotermLabel'); - print ''; - if ($user->rights->reception->creer) print ''.img_edit().''; - else print ' '; - print '
'; - print '
'; + print '
'; + print $langs->trans('IncotermLabel'); + print ''; + if ($user->rights->reception->creer) print ''.img_edit().''; + else print ' '; + print '
'; + print '
'; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); } else { 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 '
"; @@ -1662,50 +1662,50 @@ if ($action == 'create') if ($origin && $origin_id > 0) { - $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end"; - $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot"; - $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception"; - //if ($conf->delivery_note->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received"; - $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch'; - $sql .= ', p.description as product_desc'; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed"; - $sql .= ", ".MAIN_DB_PREFIX."reception as e"; - $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj"; - //if ($conf->delivery_note->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; - $sql .= " WHERE e.entity IN (".getEntity('reception').")"; - $sql .= " AND obj.fk_commande = ".$origin_id; - $sql .= " AND obj.rowid = ed.fk_commandefourndet"; - $sql .= " AND ed.fk_reception = e.rowid"; - $sql .= " AND ed.fk_reception !=".$object->id; - //if ($filter) $sql.= $filter; - $sql .= " ORDER BY obj.fk_product"; + $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end"; + $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot"; + $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception"; + //if ($conf->delivery_note->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received"; + $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch'; + $sql .= ', p.description as product_desc'; + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed"; + $sql .= ", ".MAIN_DB_PREFIX."reception as e"; + $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj"; + //if ($conf->delivery_note->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; + $sql .= " WHERE e.entity IN (".getEntity('reception').")"; + $sql .= " AND obj.fk_commande = ".$origin_id; + $sql .= " AND obj.rowid = ed.fk_commandefourndet"; + $sql .= " AND ed.fk_reception = e.rowid"; + $sql .= " AND ed.fk_reception !=".$object->id; + //if ($filter) $sql.= $filter; + $sql .= " ORDER BY obj.fk_product"; - dol_syslog("get list of reception lines", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; + dol_syslog("get list of reception lines", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; - while ($i < $num) - { - $obj = $db->fetch_object($resql); - if ($obj) - { - // $obj->rowid is rowid in $origin."det" table - $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery); - } - $i++; - } - } - //var_dump($alreadysent); + while ($i < $num) + { + $obj = $db->fetch_object($resql); + if ($obj) + { + // $obj->rowid is rowid in $origin."det" table + $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref'=>$obj->reception_ref, 'reception_id'=>$obj->reception_id, 'warehouse'=>$obj->fk_entrepot, 'qty'=>$obj->qty, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery); + } + $i++; + } + } + //var_dump($alreadysent); } // Loop on each product to send/sent for ($i = 0; $i < $num_prod; $i++) { - print ''; // id of order line + print ''; // id of order line print ''; // # @@ -1765,35 +1765,35 @@ if ($action == 'create') print ''.$lines[$i]->qty_asked.''; // Qty in other receptions (with reception and warehouse used) - if ($origin && $origin_id > 0) - { - print ''; - foreach ($alreadysent as $key => $val) - { - if ($lines[$i]->fk_commandefourndet == $key) - { - $j = 0; - foreach ($val as $receptionline_id=> $receptionline_var) - { - if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions" + if ($origin && $origin_id > 0) + { + print ''; + foreach ($alreadysent as $key => $val) + { + if ($lines[$i]->fk_commandefourndet == $key) + { + $j = 0; + foreach ($val as $receptionline_id=> $receptionline_var) + { + if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) continue; // We want to show only "other receptions" - $j++; - if ($j > 1) print '
'; - $reception_static->fetch($receptionline_var['reception_id']); - print $reception_static->getNomUrl(1); - print ' - '.$receptionline_var['qty']; + $j++; + if ($j > 1) print '
'; + $reception_static->fetch($receptionline_var['reception_id']); + print $reception_static->getNomUrl(1); + print ' - '.$receptionline_var['qty']; - $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour')); - if (!empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0) - { - $warehousestatic->fetch($receptionline_var['warehouse']); - $htmltext .= '
'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1); - } - print ' '.$form->textwithpicto('', $htmltext, 1); - } - } - } - } + $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour')); + if (!empty($conf->stock->enabled) && $receptionline_var['warehouse'] > 0) + { + $warehousestatic->fetch($receptionline_var['warehouse']); + $htmltext .= '
'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1); + } + print ' '.$form->textwithpicto('', $htmltext, 1); + } + } + } + } print ''; if ($action == 'editline' && $lines[$i]->id == $line_id) @@ -1970,7 +1970,7 @@ if ($action == 'create') if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate))) { print ''.$langs->trans("Validate").''; } else { @@ -1990,7 +1990,7 @@ if ($action == 'create') { print ''.$langs->trans("ClassifyUnbilled").''; } else { - print ''.$langs->trans("ReOpen").''; + print ''.$langs->trans("ReOpen").''; } } @@ -2026,8 +2026,8 @@ if ($action == 'create') // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on receptions instead of orders if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? { - $label = "ClassifyBilled"; - $paramaction = 'classifybilled'; + $label = "ClassifyBilled"; + $paramaction = 'classifybilled'; } print ''.$langs->trans($label).''; } @@ -2049,9 +2049,9 @@ if ($action == 'create') if ($action != 'presend' && $action != 'editline') { - print '
'; + print '
'; - $objectref = dol_sanitizeFileName($object->ref); + $objectref = dol_sanitizeFileName($object->ref); $filedir = $conf->reception->dir_output."/".$objectref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; @@ -2108,10 +2108,10 @@ if ($action == 'create') include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang); - $formmail->fromtype = (GETPOST('fromtype') ?GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user')); - if ($formmail->fromtype === 'user') { - $formmail->fromid = $user->id; - } + $formmail->fromtype = (GETPOST('fromtype') ?GETPOST('fromtype') : (!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE) ? $conf->global->MAIN_MAIL_DEFAULT_FROMTYPE : 'user')); + if ($formmail->fromtype === 'user') { + $formmail->fromid = $user->id; + } $formmail->trackid = 'shi'.$object->id; if (!empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set { @@ -2147,7 +2147,7 @@ if ($action == 'create') $contactarr = array(); if (is_object($objectsrc)) // For the case the reception was created without orders { - $contactarr = $objectsrc->liste_contact(-1, 'external'); + $contactarr = $objectsrc->liste_contact(-1, 'external'); } if (is_array($contactarr) && count($contactarr) > 0) { foreach ($contactarr as $contact) { diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 25690279f71..782728bfbd0 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -57,35 +57,35 @@ class Reception extends CommonObject */ public $picto = 'dollyrevert'; - public $socid; - public $ref_supplier; + public $socid; + public $ref_supplier; - /** - * @var int Ref int - * @deprecated - */ - public $ref_int; + /** + * @var int Ref int + * @deprecated + */ + public $ref_int; - public $brouillon; - public $entrepot_id; - public $lines = array(); - public $tracking_number; - public $tracking_url; - public $billed; - public $model_pdf; + public $brouillon; + public $entrepot_id; + public $lines = array(); + public $tracking_number; + public $tracking_url; + public $billed; + public $model_pdf; - public $trueWeight; - public $weight_units; - public $trueWidth; - public $width_units; - public $trueHeight; - public $height_units; - public $trueDepth; - public $depth_units; + public $trueWeight; + public $weight_units; + public $trueWidth; + public $width_units; + public $trueHeight; + public $height_units; + public $trueDepth; + public $depth_units; // A denormalized value - public $trueSize; + public $trueSize; - public $date_delivery; // Date delivery planed + public $date_delivery; // Date delivery planed /** @@ -103,8 +103,8 @@ class Reception extends CommonObject */ public $date_valid; - public $meths; - public $listmeths; // List of carriers + public $meths; + public $listmeths; // List of carriers const STATUS_DRAFT = 0; @@ -118,7 +118,7 @@ class Reception extends CommonObject * * @param DoliDB $db Database handler */ - public function __construct($db) + public function __construct($db) { $this->db = $db; $this->lines = array(); @@ -145,33 +145,33 @@ class Reception extends CommonObject * @param Societe $soc Thirdparty object * @return string Free reference for contract */ - public function getNextNumRef($soc) + public function getNextNumRef($soc) { global $langs, $conf; $langs->load("receptions"); - if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) - { + if (!empty($conf->global->RECEPTION_ADDON_NUMBER)) + { $mybool = false; $file = $conf->global->RECEPTION_ADDON_NUMBER.".php"; $classname = $conf->global->RECEPTION_ADDON_NUMBER; - // Include file with class - $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); + // Include file with class + $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); - foreach ($dirmodels as $reldir) { - $dir = dol_buildpath($reldir."core/modules/reception/"); + foreach ($dirmodels as $reldir) { + $dir = dol_buildpath($reldir."core/modules/reception/"); - // Load file with numbering class (if found) - $mybool |= @include_once $dir.$file; - } + // Load file with numbering class (if found) + $mybool |= @include_once $dir.$file; + } - if (!$mybool) - { - dol_print_error('', "Failed to include file ".$file); - return ''; - } + if (!$mybool) + { + dol_print_error('', "Failed to include file ".$file); + return ''; + } $obj = new $classname(); @@ -185,10 +185,10 @@ class Reception extends CommonObject dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error); return ""; } - } else { - print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined"); - return ""; - } + } else { + print $langs->trans("Error")." ".$langs->trans("Error_RECEPTION_ADDON_NUMBER_NotDefined"); + return ""; + } } /** @@ -198,7 +198,7 @@ class Reception extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 si erreur, id reception creee si ok */ - public function create($user, $notrigger = 0) + public function create($user, $notrigger = 0) { global $conf, $hookmanager; @@ -264,8 +264,8 @@ class Reception extends CommonObject $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); $sql .= ", ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null"); $sql .= ", ".(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null"); - $sql .= ", ".(int) $this->fk_incoterms; - $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; + $sql .= ", ".(int) $this->fk_incoterms; + $sql .= ", '".$this->db->escape($this->location_incoterms)."'"; $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); @@ -313,10 +313,10 @@ class Reception extends CommonObject if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_CREATE', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('RECEPTION_CREATE', $user); + if ($result < 0) { $error++; } + // End call triggers } if (!$error) @@ -354,10 +354,10 @@ class Reception extends CommonObject * @param int $id Id of object to load * @param string $ref Ref of object * @param string $ref_ext External reference of object - * @param string $notused Internal reference of other object + * @param string $notused Internal reference of other object * @return int >0 if OK, 0 if not found, <0 if KO */ - public function fetch($id, $ref = '', $ref_ext = '', $notused = '') + public function fetch($id, $ref = '', $ref_ext = '', $notused = '') { global $conf; @@ -370,16 +370,16 @@ class Reception extends CommonObject $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'; - $sql .= ', i.libelle as label_incoterms'; + $sql .= ', e.fk_incoterms, e.location_incoterms'; + $sql .= ', i.libelle as label_incoterms'; $sql .= " FROM ".MAIN_DB_PREFIX."reception as e"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = e.rowid AND el.targettype = '".$this->db->escape($this->element)."'"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid'; $sql .= " WHERE e.entity IN (".getEntity('reception').")"; if ($id) $sql .= " AND e.rowid=".$id; - if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; - if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; - if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; + if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; + if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; + if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $result = $this->db->query($sql); @@ -481,14 +481,14 @@ class Reception extends CommonObject * Validate object and update stock if option enabled * * @param User $user Object user that validate - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if OK, >0 if KO */ - public function valid($user, $notrigger = 0) + public function valid($user, $notrigger = 0) { global $conf, $langs; - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; dol_syslog(get_class($this)."::valid"); @@ -499,8 +499,8 @@ class Reception extends CommonObject return 0; } - if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) { $this->error = 'Permission denied'; dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); @@ -524,7 +524,7 @@ class Reception extends CommonObject $numref = $this->ref; } - $this->newref = dol_sanitizeFileName($numref); + $this->newref = dol_sanitizeFileName($numref); $now = dol_now(); @@ -594,7 +594,7 @@ class Reception extends CommonObject // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record. - // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version) + // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version) $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionValidatedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); if ($result < 0) { $error++; @@ -614,22 +614,22 @@ class Reception extends CommonObject // Change status of order to "reception in process" $ret = $this->setStatut(4, $this->origin_id, 'commande_fournisseur'); - if (!$ret) + if (!$ret) { - $error++; + $error++; } if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_VALIDATE', $user); - if ($result < 0) { $error++; } - // End call triggers + // Call trigger + $result = $this->call_trigger('RECEPTION_VALIDATE', $user); + if ($result < 0) { $error++; } + // End call triggers } if (!$error) { - $this->oldref = $this->ref; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -651,17 +651,17 @@ class Reception extends CommonObject if (@rename($dirsource, $dirdest)) { - dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref - $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { - $dirsource = $fileentry['name']; - $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); - $dirsource = $fileentry['path'].'/'.$dirsource; - $dirdest = $fileentry['path'].'/'.$dirdest; - @rename($dirsource, $dirdest); - } + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles = dol_dir_list($conf->reception->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + foreach ($listoffiles as $fileentry) + { + $dirsource = $fileentry['name']; + $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); + $dirsource = $fileentry['path'].'/'.$dirsource; + $dirdest = $fileentry['path'].'/'.$dirdest; + @rename($dirsource, $dirdest); + } } } } @@ -681,8 +681,8 @@ class Reception extends CommonObject } else { foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + dol_syslog(get_class($this)."::valid ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); return -1 * $error; @@ -706,7 +706,7 @@ class Reception extends CommonObject * @param string $batch Lot number * @return int <0 if KO, >0 if OK */ - public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '') + public function addline($entrepot_id, $id, $qty, $array_options = 0, $comment = '', $eatby = '', $sellby = '', $batch = '') { global $conf, $langs, $user; @@ -726,7 +726,7 @@ class Reception extends CommonObject if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS)) { - $langs->load("errors"); + $langs->load("errors"); $this->error = $langs->trans("ErrorWarehouseRequiredIntoReceptionLine"); return -1; } @@ -755,16 +755,16 @@ class Reception extends CommonObject } - /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, >0 if OK - */ - public function update($user = null, $notrigger = 0) - { - global $conf; + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update($user = null, $notrigger = 0) + { + global $conf; $error = 0; // Clean parameters @@ -793,8 +793,8 @@ class Reception extends CommonObject // Check parameters // Put here code to add control on parameters values - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET"; + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."reception SET"; $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; @@ -820,32 +820,32 @@ class Reception extends CommonObject $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; $sql .= " entity=".$conf->entity; - $sql .= " WHERE rowid=".$this->id; + $sql .= " WHERE rowid=".$this->id; $this->db->begin(); dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$error) { if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('RECEPTION_MODIFY', $user); - if ($result < 0) { $error++; } - // End call triggers - } + // Call trigger + $result = $this->call_trigger('RECEPTION_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers + } } - // Commit or rollback + // 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); + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); return -1 * $error; @@ -861,7 +861,7 @@ class Reception extends CommonObject * @param User $user Object user * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ - public function delete(User $user) + public function delete(User $user) { global $conf, $langs, $user; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -909,9 +909,9 @@ class Reception extends CommonObject if (!$error) { - $main = MAIN_DB_PREFIX.'commande_fournisseur_dispatch'; - $ef = $main."_extrafields"; - $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_reception = ".$this->id.")"; + $main = MAIN_DB_PREFIX.'commande_fournisseur_dispatch'; + $ef = $main."_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_reception = ".$this->id.")"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch"; $sql .= " WHERE fk_reception = ".$this->id; @@ -936,18 +936,18 @@ class Reception extends CommonObject if (!empty($this->origin) && $this->origin_id > 0) { - $this->fetch_origin(); - $origin = $this->origin; - if ($this->$origin->statut == 4) // If order source of reception is "partially received" - { - // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress" - $this->$origin->loadReceptions(); - //var_dump($this->$origin->receptions);exit; - if (count($this->$origin->receptions) <= 0) - { - $this->$origin->setStatut(3); // ordered - } - } + $this->fetch_origin(); + $origin = $this->origin; + if ($this->$origin->statut == 4) // If order source of reception is "partially received" + { + // Check if there is no more reception. If not, we can move back status of order to "validated" instead of "reception in progress" + $this->$origin->loadReceptions(); + //var_dump($this->$origin->receptions);exit; + if (count($this->$origin->receptions) <= 0) + { + $this->$origin->setStatut(3); // ordered + } + } } if (!$error) @@ -1003,13 +1003,13 @@ class Reception extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load lines * * @return int >0 if OK, Otherwise if KO */ - public function fetch_lines() + public function fetch_lines() { // phpcs:enable dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php'); @@ -1060,22 +1060,22 @@ class Reception extends CommonObject } /** - * Return clicable link of object (with eventually picto) - * - * @param int $withpicto Add picto into link - * @param int $option Where point the link - * @param int $max Max length to show - * @param int $short Use short labels - * @param int $notooltip 1=No tooltip - * @return string String with URL - */ - public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0) + * Return clicable link of object (with eventually picto) + * + * @param int $withpicto Add picto into link + * @param int $option Where point the link + * @param int $max Max length to show + * @param int $short Use short labels + * @param int $notooltip 1=No tooltip + * @return string String with URL + */ + public function getNomUrl($withpicto = 0, $option = 0, $max = 0, $short = 0, $notooltip = 0) { global $conf, $langs; $result = ''; $label = img_picto('', $this->picto).' '.$langs->trans("Reception").''; - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - $label .= '
'.$langs->trans('RefSupplier').': '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client); + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + $label .= '
'.$langs->trans('RefSupplier').': '.($this->ref_supplier ? $this->ref_supplier : $this->ref_client); $url = DOL_URL_ROOT.'/reception/card.php?id='.$this->id; @@ -1084,17 +1084,17 @@ class Reception extends CommonObject $linkclose = ''; if (empty($notooltip)) { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label = $langs->trans("Reception"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("Reception"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; } - $linkstart = ''; + $linkstart = ''; $linkend = ''; if ($withpicto) $result .= ($linkstart.img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend); @@ -1104,15 +1104,15 @@ class Reception extends CommonObject } /** - * Return status label - * - * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto - * @return string Libelle - */ - public function getLibStatut($mode = 0) - { - return $this->LibStatut($this->statut, $mode); - } + * Return status label + * + * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto + * @return string Libelle + */ + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->statut, $mode); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** @@ -1122,30 +1122,30 @@ class Reception extends CommonObject * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto * @return string Label of status */ - public function LibStatut($status, $mode) - { - // phpcs:enable - global $langs; + public function LibStatut($status, $mode) + { + // phpcs:enable + global $langs; - $labelStatus = $langs->trans($this->statuts[$status]); - $labelStatusShort = $langs->trans($this->statutshorts[$status]); + $labelStatus = $langs->trans($this->statuts[$status]); + $labelStatusShort = $langs->trans($this->statutshorts[$status]); - $statusType = 'status'.$status; - if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; - if ($status == self::STATUS_CLOSED) $statusType = 'status6'; + $statusType = 'status'.$status; + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; + if ($status == self::STATUS_CLOSED) $statusType = 'status6'; - return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); + return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); } /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() - { + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { global $langs; include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; @@ -1154,7 +1154,7 @@ class Reception extends CommonObject dol_syslog(get_class($this)."::initAsSpecimen"); - // Load array of products prodids + // Load array of products prodids $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; @@ -1197,11 +1197,11 @@ class Reception extends CommonObject $this->commande_id = 0; $this->commande = $order; - $this->origin_id = 1; - $this->origin = 'commande'; + $this->origin_id = 1; + $this->origin = 'commande'; - $this->note_private = 'Private note'; - $this->note_public = 'Public note'; + $this->note_private = 'Private note'; + $this->note_public = 'Public note'; $nbp = 5; $xnbp = 0; @@ -1250,7 +1250,7 @@ class Reception extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch deliveries method and return an array. Load array this->meths(rowid=>label). * @@ -1278,101 +1278,101 @@ class Reception extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Fetch all deliveries method and return an array. Load array this->listmeths. - * - * @param int $id only this carrier, all if none - * @return void - */ - public function list_delivery_methods($id = '') - { - // phpcs:enable - global $langs; - - $this->listmeths = array(); - $i = 0; - - $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; - if ($id != '') $sql .= " WHERE em.rowid=".$id; - - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $this->listmeths[$i]['rowid'] = $obj->rowid; - $this->listmeths[$i]['code'] = $obj->code; - $label = $langs->trans('ReceptionMethod'.$obj->code); - $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle); - $this->listmeths[$i]['description'] = $obj->description; - $this->listmeths[$i]['tracking'] = $obj->tracking; - $this->listmeths[$i]['active'] = $obj->active; - $i++; - } - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Update/create delivery method. - * - * @param string $id id method to activate - * - * @return void - */ - public function update_delivery_method($id = '') - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Fetch all deliveries method and return an array. Load array this->listmeths. + * + * @param int $id only this carrier, all if none + * @return void + */ + public function list_delivery_methods($id = '') + { // phpcs:enable - if ($id == '') - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; - $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; - $resql = $this->db->query($sql); - } else { - $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET"; - $sql .= " code='".$this->db->escape($this->update['code'])."'"; - $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'"; - $sql .= ",description='".$this->db->escape($this->update['description'])."'"; - $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'"; - $sql .= " WHERE rowid=".$id; - $resql = $this->db->query($sql); - } - if ($resql < 0) dol_print_error($this->db, ''); - } + global $langs; + + $this->listmeths = array(); + $i = 0; + + $sql = "SELECT em.rowid, em.code, em.libelle, em.description, em.tracking, em.active"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; + if ($id != '') $sql .= " WHERE em.rowid=".$id; + + $resql = $this->db->query($sql); + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { + $this->listmeths[$i]['rowid'] = $obj->rowid; + $this->listmeths[$i]['code'] = $obj->code; + $label = $langs->trans('ReceptionMethod'.$obj->code); + $this->listmeths[$i]['libelle'] = ($label != 'ReceptionMethod'.$obj->code ? $label : $obj->libelle); + $this->listmeths[$i]['description'] = $obj->description; + $this->listmeths[$i]['tracking'] = $obj->tracking; + $this->listmeths[$i]['active'] = $obj->active; + $i++; + } + } + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Activate delivery method. - * - * @param int $id id method to activate - * - * @return void - */ - public function activ_delivery_method($id) - { + /** + * Update/create delivery method. + * + * @param string $id id method to activate + * + * @return void + */ + public function update_delivery_method($id = '') + { // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; - $sql .= ' WHERE rowid='.$id; + if ($id == '') + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; + $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; + $resql = $this->db->query($sql); + } else { + $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET"; + $sql .= " code='".$this->db->escape($this->update['code'])."'"; + $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'"; + $sql .= ",description='".$this->db->escape($this->update['description'])."'"; + $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'"; + $sql .= " WHERE rowid=".$id; + $resql = $this->db->query($sql); + } + if ($resql < 0) dol_print_error($this->db, ''); + } - $resql = $this->db->query($sql); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * DesActivate delivery method. - * - * @param int $id id method to desactivate - * - * @return void - */ - public function disable_delivery_method($id) - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Activate delivery method. + * + * @param int $id id method to activate + * + * @return void + */ + public function activ_delivery_method($id) + { // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; - $sql .= ' WHERE rowid='.$id; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; + $sql .= ' WHERE rowid='.$id; - $resql = $this->db->query($sql); - } + $resql = $this->db->query($sql); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * DesActivate delivery method. + * + * @param int $id id method to desactivate + * + * @return void + */ + public function disable_delivery_method($id) + { + // phpcs:enable + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; + $sql .= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + } /** @@ -1381,7 +1381,7 @@ class Reception extends CommonObject * @param string $value Value * @return void */ - public function getUrlTrackingStatus($value = '') + public function getUrlTrackingStatus($value = '') { if (!empty($this->shipping_method_id)) { @@ -1413,7 +1413,7 @@ class Reception extends CommonObject * * @return int <0 if KO, >0 if OK */ - public function setClosed() + public function setClosed() { global $conf, $langs, $user; @@ -1500,8 +1500,8 @@ class Reception extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } } else { @@ -1511,9 +1511,9 @@ class Reception extends CommonObject $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ReceptionClassifyClosedInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; } } } @@ -1526,36 +1526,36 @@ class Reception extends CommonObject // Call trigger if (!$error) { - $result = $this->call_trigger('RECEPTION_CLOSED', $user); - if ($result < 0) { - $error++; - } + $result = $this->call_trigger('RECEPTION_CLOSED', $user); + if ($result < 0) { + $error++; + } } } else { dol_print_error($this->db); - $error++; + $error++; } if (!$error) { - $this->db->commit(); - return 1; + $this->db->commit(); + return 1; } else { - $this->db->rollback(); - return -1; + $this->db->rollback(); + return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Classify the reception as invoiced (used when WORKFLOW_BILL_ON_RECEPTION is on) * * @return int <0 if ko, >0 if ok */ - public function set_billed() + public function set_billed() { // phpcs:enable - global $user; + global $user; $error = 0; $this->db->begin(); @@ -1595,7 +1595,7 @@ class Reception extends CommonObject * * @return int <0 if ko, >0 if ok */ - public function reOpen() + public function reOpen() { global $conf, $langs, $user; @@ -1655,8 +1655,8 @@ class Reception extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } } else { @@ -1665,9 +1665,9 @@ class Reception extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionUnClassifyCloseddInDolibarr", $numref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; } } } @@ -1679,11 +1679,11 @@ class Reception extends CommonObject if (!$error) { - // Call trigger - $result = $this->call_trigger('RECEPTION_REOPEN', $user); - if ($result < 0) { - $error++; - } + // Call trigger + $result = $this->call_trigger('RECEPTION_REOPEN', $user); + if ($result < 0) { + $error++; + } } if ($this->origin == 'order_supplier') { @@ -1707,41 +1707,41 @@ class Reception extends CommonObject } /** - * Set draft status - * - * @param User $user Object user that modify - * @return int <0 if KO, >0 if OK - */ - public function setDraft($user) - { + * Set draft status + * + * @param User $user Object user that modify + * @return int <0 if KO, >0 if OK + */ + public function setDraft($user) + { // phpcs:enable - global $conf, $langs; + global $conf, $langs; - $error = 0; + $error = 0; - // Protection - if ($this->statut <= self::STATUS_DRAFT) - { - return 0; - } + // Protection + if ($this->statut <= self::STATUS_DRAFT) + { + return 0; + } - if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) - { - $this->error = 'Permission denied'; - return -1; - } + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->reception->reception_advance->validate)))) + { + $this->error = 'Permission denied'; + return -1; + } - $this->db->begin(); + $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."reception"; - $sql .= " SET fk_statut = ".self::STATUS_DRAFT; - $sql .= " WHERE rowid = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."reception"; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT; + $sql .= " WHERE rowid = ".$this->id; - dol_syslog(__METHOD__, LOG_DEBUG); - if ($this->db->query($sql)) - { - // If stock increment is done on closing + dol_syslog(__METHOD__, LOG_DEBUG); + if ($this->db->query($sql)) + { + // If stock increment is done on closing if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; @@ -1784,8 +1784,8 @@ class Reception extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref)); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; $error++; break; } @@ -1795,9 +1795,9 @@ class Reception extends CommonObject // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ReceptionBackToDraftInDolibarr", $this->ref), $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch); if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; break; + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; } } } @@ -1807,11 +1807,11 @@ class Reception extends CommonObject } } - if (!$error) { - // Call trigger - $result = $this->call_trigger('RECEPTION_UNVALIDATE', $user); - if ($result < 0) $error++; - } + if (!$error) { + // Call trigger + $result = $this->call_trigger('RECEPTION_UNVALIDATE', $user); + if ($result < 0) $error++; + } if ($this->origin == 'order_supplier') { if (!empty($this->origin) && $this->origin_id > 0) @@ -1843,20 +1843,20 @@ class Reception extends CommonObject } } - if (!$error) { - $this->statut = self::STATUS_DRAFT; - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } + if (!$error) { + $this->statut = self::STATUS_DRAFT; + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return -1; + } + } else { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } /** * Create a document onto disk according to template module.