Merge pull request #2625 from marcosgdf/bug-2601

Fix bug #2601 Supplier orderstoinvoice does not work with PostgreSQL
This commit is contained in:
Juanjo Menent 2015-04-18 15:03:01 +02:00
commit 459737e171

View File

@ -7,6 +7,7 @@
* Copyright (C) 2012 David Rodriguez Martinez <davidrm146@gmail.com> * Copyright (C) 2012 David Rodriguez Martinez <davidrm146@gmail.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -160,32 +161,14 @@ if (($action == 'create' || $action == 'add') && empty($mesgs)) {
$object->date_echeance = $object->calculate_date_lim_reglement(); $object->date_echeance = $object->calculate_date_lim_reglement();
if ($_POST['origin'] && $_POST['originid']) { if ($_POST['origin'] && $_POST['originid']) {
$object->origin = $_POST['origin'];
$object->origin_id = $orders_id[$ii];
$object->linked_objects = $orders_id; $object->linked_objects = $orders_id;
$id = $object->create($user); $id = $object->create($user);
if ($id > 0) { if ($id > 0) {
foreach ( $orders_id as $origin => $origin_id ) { foreach ( $orders_id as $origin => $origin_id ) {
$origin_id = (! empty($origin_id) ? $origin_id : $object->origin_id); $origin_id = (! empty($origin_id) ? $origin_id : $orders_id[$ii]);
$db->begin();
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element (";
$sql .= "fk_source";
$sql .= ", sourcetype";
$sql .= ", fk_target";
$sql .= ", targettype";
$sql .= ") VALUES (";
$sql .= $origin_id;
$sql .= ", '" . $object->origin . "'";
$sql .= ", " . $id;
$sql .= ", '" . $object->element . "'";
$sql .= ")";
if ($db->query($sql)) { $object->add_object_linked($_POST['origin'], $origin_id);
$db->commit();
} else {
$db->rollback();
}
} }
while ( $ii < $nn ) { while ( $ii < $nn ) {
@ -577,7 +560,7 @@ if (($action != 'create' && $action != 'add') || ! empty($mesgs)) {
print '<div align="right">'; print '<div align="right">';
print '<input type="hidden" name="socid" value="' . $socid . '">'; print '<input type="hidden" name="socid" value="' . $socid . '">';
print '<input type="hidden" name="action" value="create">'; print '<input type="hidden" name="action" value="create">';
print '<input type="hidden" name="origin" value="commande"><br>'; print '<input type="hidden" name="origin" value="order_supplier"><br>';
// print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>'; // print '<a class="butAction" href="index.php">'.$langs->trans("GoBack").'</a>';
print '<input type="submit" class="butAction" value="' . $langs->trans("GenerateBill") . '">'; print '<input type="submit" class="butAction" value="' . $langs->trans("GenerateBill") . '">';
print '</div>'; print '</div>';