+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+/* To call this template, you must define
+ * $textobject
+ * $langs
+ * $extrafield
+ * $elementtype
+ */
+?>
+
+
+trans("DefineHereComplementaryAttributes",$textobject).' '."\n";
+print ' ';
+
+// Load attribute_label
+$extrafields->fetch_name_optionals_label($elementtype);
+
+print "";
+
+print '';
+print ''.$langs->trans("Position").' ';
+print ''.$langs->trans("Label").' ';
+print ''.$langs->trans("AttributeCode").' ';
+print ''.$langs->trans("Type").' ';
+print ''.$langs->trans("Size").' ';
+print ''.$langs->trans("Unique").' ';
+print ''.$langs->trans("Required").' ';
+print ''.$langs->trans("AlwaysEditable").' ';
+print ' ';
+print " \n";
+
+$var=True;
+foreach($extrafields->attribute_type as $key => $value)
+{
+ $var=!$var;
+ print "";
+ print "".$extrafields->attribute_pos[$key]." \n";
+ print "".$extrafields->attribute_label[$key]." \n";
+ print "".$key." \n";
+ print "".$type2label[$extrafields->attribute_type[$key]]." \n";
+ print ''.$extrafields->attribute_size[$key]." \n";
+ print ''.yn($extrafields->attribute_unique[$key])." \n";
+ print ''.yn($extrafields->attribute_required[$key])." \n";
+ print ''.yn($extrafields->attribute_alwayseditable[$key])." \n";
+ print ''.img_edit().' ';
+ print " ".img_delete()." \n";
+ print " ";
+ // $i++;
+}
+
+print "
";
+
+?>
+
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index bce94c70a57..8a98ac2f613 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -263,7 +263,8 @@ else {
table_element_line=='commandedet') {
$newline = new OrderLine($this->db);
}
@@ -276,6 +277,12 @@ else {
elseif ($this->table_element_line=='contratdet') {
$newline = new ContratLigne($this->db);
}
+ elseif ($this->table_element_line=='commande_fournisseurdet') {
+ $newline = new CommandeFournisseurLigne($this->db);
+ }
+ elseif ($this->table_element_line=='facture_fourn_det') {
+ $newline = new FactureFournisseurLigne($this->db);
+ }
if (is_object($newline)) {
print $newline->showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay+8));
}
diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index ae2238e06f2..98f1b842f1a 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -43,7 +43,7 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
// Define colspan for button Add
$colspan = 3; // Col total ht + col edit + col delete
if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
-if (in_array($object->element,array('propal','facture','invoice','commande','order'))) $colspan++; // With this, there is a column move button
+if (in_array($object->element,array('propal','facture','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
?>
@@ -109,20 +109,18 @@ $coldisplay=-1; // We remove first td
}
$coldisplay++;
- print ' situation_counter > 1) {
- print 'readonly="readonly" ';
- }
+ print ' situation_counter > 1) print ' readonly="readonly"';
print '> ';
- if ($inputalsopricewithtax) {
+ if ($inputalsopricewithtax)
+ {
$coldisplay++;
- print ' situation_counter > 1) {
- print 'readonly="readonly" ';
- }
+ print ' situation_counter > 1) print ' readonly="readonly"';
print '> ';
- } ?>
+ }
+ ?>
info_bits & 2) != 2) {
@@ -130,11 +128,9 @@ $coldisplay=-1; // We remove first td
// for example always visible on invoice but must be visible only if stock module on and stock decrease option is on invoice validation and status is not validated
// must also not be output for most entities (proposal, intervention, ...)
//if($line->qty > $line->stock) print img_picto($langs->trans("StockTooLow"),"warning", 'style="vertical-align: bottom;"')." ";
- print ' situation_counter > 1) {
- print 'readonly="readonly" ';
- }
- print '/>';
+ print ' situation_counter > 1) print ' readonly="readonly"';
+ print '>';
} else { ?>
@@ -142,11 +138,9 @@ $coldisplay=-1; // We remove first td
info_bits & 2) != 2) {
- print ' situation_counter > 1) {
- print 'readonly="readonly" ';
- }
- print '/>%';
+ print ' situation_counter > 1) print ' readonly="readonly"';
+ print '>%';
} else { ?>
@@ -189,7 +183,8 @@ $coldisplay=-1; // We remove first td
$coldisplay++;
}
}
- } ?>
+ }
+ ?>
@@ -199,7 +194,8 @@ $coldisplay=-1; // We remove first td
showOptionals($extrafieldsline,'edit',array('style'=>$bc[$var],'colspan'=>$coldisplay));
}
?>
diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php
index 2e1cc0f3678..0664d471dec 100644
--- a/htdocs/core/tpl/objectline_view.tpl.php
+++ b/htdocs/core/tpl/objectline_view.tpl.php
@@ -25,20 +25,21 @@
* $langs
* $dateSelector
* $forceall (0 by default, 1 for supplier invoices/orders)
+ * $element (used to test $user->rights->$element->creer)
+ * $permtoedit (used to replace test $user->rights->$element->creer)
* $senderissupplier (0 by default, 1 for supplier invoices/orders)
* $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
+ * $usemargins (0 to disable all margins columns, 1 to show according to margin setup)
*
* $type, $text, $description, $line
*/
-$usemargins=0;
-if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1;
-
-global $forceall, $senderissupplier, $inputalsopricewithtax;
+global $forceall, $senderissupplier, $inputalsopricewithtax, $usemargins;
if (empty($dateSelector)) $dateSelector=0;
if (empty($forceall)) $forceall=0;
if (empty($senderissupplier)) $senderissupplier=0;
if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
+if (empty($usemargins)) $usemargins=0;
?>
@@ -83,7 +84,8 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
}
else
{
- if ($line->fk_product > 0) {
+ if ($line->fk_product > 0)
+ {
echo $form->textwithtooltip($text,$description,3,'','',$i,0,(!empty($line->fk_parent_line)?img_picto('', 'rightarrow'):''));
@@ -96,7 +98,9 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
print (! empty($line->description) && $line->description!=$line->product_label)?' '.dol_htmlentitiesbr($line->description):'';
}
- } else {
+ }
+ else
+ {
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
@@ -118,10 +122,10 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
tva_tx,'%',$line->info_bits); ?>
- subprice); ?>
+ pu_ht)?price($line->pu_ht):price($line->subprice)); ?>
-
+ pu_ttc)?price($line->pu_ttc):price($line->subprice)); ?>
@@ -135,7 +139,11 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
remise_percent) && $line->special_code != 3) { ?>
- remise_percent,$langs); ?>
+ remise_percent,$langs);
+ ?>
' . $line->situation_percent . '%';
}
- if (! empty($conf->margin->enabled) && empty($user->societe_id)) {
- $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
- ?>
+ if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id))
+ {
+ $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT);
+ ?>
pa_ht); ?>
- global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) {?>
+ global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { ?>
pa_ht == 0)?'n/a':price($line->marge_tx, null, null, null, null, $rounding).'%'); ?>
- global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {?>
+ global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) {?>
marque_tx, null, null, null, null, $rounding).'%'; ?>
-
+
special_code == 3) { ?>
trans('Option'); ?>
@@ -163,7 +173,7 @@ if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0;
total_ht); ?>
- statut == 0 && $user->rights->$element->creer) { ?>
+ statut == 0 && ($user->rights->$element->creer || $permtoedit)) { ?>
info_bits & 2) == 2) { ?>
diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php
index 723660f1d9c..5f2ef68b194 100644
--- a/htdocs/cron/class/cronjob.class.php
+++ b/htdocs/cron/class/cronjob.class.php
@@ -718,6 +718,8 @@ class Cronjob extends CommonObject
$object=new Cronjob($this->db);
+ $object->context['createfromclone'] = 'createfromclone';
+
$this->db->begin();
// Load source object
@@ -744,6 +746,8 @@ class Cronjob extends CommonObject
}
+ unset($this->context['createfromclone']);
+
// End
if (! $error)
{
diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php
index a8e10f40464..d6700ac26a2 100755
--- a/htdocs/expensereport/list.php
+++ b/htdocs/expensereport/list.php
@@ -1,8 +1,9 @@
- * Copyright (C) 2004-2008 Laurent Destailleur
- * Copyright (C) 2004 Eric Seigne
- * Copyright (C) 2005-2009 Regis Houssin
+/* Copyright (C) 2003 Rodolphe Quiedeville
+ * Copyright (C) 2004-2008 Laurent Destailleur
+ * Copyright (C) 2004 Eric Seigne
+ * Copyright (C) 2005-2009 Regis Houssin
+ * Copyright (C) 2015 Alexandre Spangaro
*
* 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
@@ -63,7 +64,7 @@ $html = new Form($db);
$formother = new FormOther($db);
$expensereporttmp=new ExpenseReport($db);
-llxHeader('', $langs->trans("ListOfExpenseReports"));
+llxHeader('', $langs->trans("ListOfTrips"));
$max_year = 5;
$min_year = 5;
@@ -302,7 +303,7 @@ if ($resql)
print "";
print '';
$db->free($resql);
diff --git a/htdocs/fichinter/admin/fichinter_extrafields.php b/htdocs/fichinter/admin/fichinter_extrafields.php
index 8cb95a30f63..c5420948ab3 100644
--- a/htdocs/fichinter/admin/fichinter_extrafields.php
+++ b/htdocs/fichinter/admin/fichinter_extrafields.php
@@ -62,60 +62,18 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
* View
*/
+$textobject=$langs->transnoentitiesnoconv("Interventions");
llxHeader();
-$textobject=$langs->transnoentitiesnoconv("Interventions");
-
$linkback=''.$langs->trans("BackToModuleList").' ';
print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup');
-
$head=fichinter_admin_prepare_head();
dol_fiche_head($head, 'attributes', $langs->trans("Interventions"), 0, 'intervention');
-
-print $langs->trans("DefineHereComplementaryAttributes",$textobject).' '."\n";
-print ' ';
-
-// Load attribute_label
-$extrafields->fetch_name_optionals_label($elementtype);
-
-print "";
-
-print '';
-print ''.$langs->trans("Position").' ';
-print ''.$langs->trans("Label").' ';
-print ''.$langs->trans("AttributeCode").' ';
-print ''.$langs->trans("Type").' ';
-print ''.$langs->trans("Size").' ';
-print ''.$langs->trans("Unique").' ';
-print ''.$langs->trans("Required").' ';
-print ''.$langs->trans("AlwaysEditable").' ';
-print ' ';
-print " \n";
-
-$var=True;
-foreach($extrafields->attribute_type as $key => $value)
-{
- $var=!$var;
- print "";
- print "".$extrafields->attribute_pos[$key]." \n";
- print "".$extrafields->attribute_label[$key]." \n";
- print "".$key." \n";
- print "".$type2label[$extrafields->attribute_type[$key]]." \n";
- print ''.$extrafields->attribute_size[$key]." \n";
- print ''.yn($extrafields->attribute_unique[$key])." \n";
- print ''.yn($extrafields->attribute_required[$key])." \n";
- print ''.yn($extrafields->attribute_alwayseditable[$key])." \n"; // TODO This must be generalised into all page to admin extrafield. Mutualize code here is easy and will save a lot of code
- print ''.img_edit().' ';
- print " ".img_delete()." \n";
- print " ";
- // $i++;
-}
-
-print "
";
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
dol_fiche_end();
diff --git a/htdocs/fichinter/admin/fichinterdet_extrafields.php b/htdocs/fichinter/admin/fichinterdet_extrafields.php
index 7f8b5193631..aaaa497f959 100644
--- a/htdocs/fichinter/admin/fichinterdet_extrafields.php
+++ b/htdocs/fichinter/admin/fichinterdet_extrafields.php
@@ -62,11 +62,10 @@ require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
* View
*/
+$textobject=$langs->transnoentitiesnoconv("Interventions");
llxHeader();
-$textobject=$langs->transnoentitiesnoconv("Interventions");
-
$linkback=''.$langs->trans("BackToModuleList").' ';
print_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'setup');
@@ -75,45 +74,7 @@ $head=fichinter_admin_prepare_head();
dol_fiche_head($head, 'attributesdet', $langs->trans("Interventions"), 0, 'intervention');
-
-print $langs->trans("DefineHereComplementaryAttributes",$textobject).' '."\n";
-print ' ';
-
-// Load attribute_label
-$extrafields->fetch_name_optionals_label($elementtype);
-
-print "";
-
-print '';
-print ''.$langs->trans("Position").' ';
-print ''.$langs->trans("Label").' ';
-print ''.$langs->trans("AttributeCode").' ';
-print ''.$langs->trans("Type").' ';
-print ''.$langs->trans("Size").' ';
-print ''.$langs->trans("Unique").' ';
-print ''.$langs->trans("Required").' ';
-print ' ';
-print " \n";
-
-$var=True;
-foreach($extrafields->attribute_type as $key => $value)
-{
- $var=!$var;
- print "";
- print "".$extrafields->attribute_pos[$key]." \n";
- print "".$extrafields->attribute_label[$key]." \n";
- print "".$key." \n";
- print "".$type2label[$extrafields->attribute_type[$key]]." \n";
- print ''.$extrafields->attribute_size[$key]." \n";
- print ''.yn($extrafields->attribute_unique[$key])." \n";
- print ''.yn($extrafields->attribute_required[$key])." \n";
- print ''.img_edit().' ';
- print " ".img_delete()." \n";
- print " ";
- // $i++;
-}
-
-print "
";
+require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
dol_fiche_end();
diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php
index 1746db04abf..661ffc9af30 100644
--- a/htdocs/fichinter/card.php
+++ b/htdocs/fichinter/card.php
@@ -206,9 +206,9 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
// Extrafields
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
- $array_option = $extrafields->getOptionalsFromPost($extralabels);
+ $array_options = $extrafields->getOptionalsFromPost($extralabels);
- $object->array_options = $array_option;
+ $object->array_options = $array_options;
$id = $object->create($user);
@@ -288,7 +288,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
+ $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
$result = $object->addline(
@@ -297,7 +297,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
$desc,
$date_intervention,
$duration,
- $array_option
+ $array_options
);
if ($result < 0)
@@ -327,9 +327,9 @@ else if ($action == 'add' && $user->rights->ficheinter->creer)
// Extrafields
$extrafields = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
- $array_option = $extrafields->getOptionalsFromPost($extralabels);
+ $array_options = $extrafields->getOptionalsFromPost($extralabels);
- $object->array_options = $array_option;
+ $object->array_options = $array_options;
$result = $object->create($user);
if ($result > 0)
@@ -470,7 +470,7 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
+ $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
$result=$object->addline(
$user,
@@ -478,7 +478,7 @@ else if ($action == "addline" && $user->rights->ficheinter->creer)
$desc,
$date_intervention,
$duration,
- $array_option
+ $array_options
);
// Define output language
@@ -568,8 +568,8 @@ else if ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST(
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_option = $extrafieldsline->getOptionalsFromPost($extralabelsline);
- $objectline->array_options = $array_option;
+ $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
+ $objectline->array_options = $array_options;
$result = $objectline->update($user);
if ($result < 0)
diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php
index 6ec66add085..7be3b0bf3bd 100644
--- a/htdocs/fichinter/class/fichinter.class.php
+++ b/htdocs/fichinter/class/fichinter.class.php
@@ -889,10 +889,10 @@ class Fichinter extends CommonObject
* @param string $desc Line description
* @param date $date_intervention Intervention date
* @param int $duration Intervention duration
- * @param array $array_option Array option
+ * @param array $array_options Array option
* @return int >0 if ok, <0 if ko
*/
- function addline($user,$fichinterid, $desc, $date_intervention, $duration, $array_option='')
+ function addline($user,$fichinterid, $desc, $date_intervention, $duration, $array_options='')
{
dol_syslog(get_class($this)."::addline $fichinterid, $desc, $date_intervention, $duration");
@@ -908,8 +908,8 @@ class Fichinter extends CommonObject
$line->datei = $date_intervention;
$line->duration = $duration;
- if (is_array($array_option) && count($array_option)>0) {
- $line->array_options=$array_option;
+ if (is_array($array_options) && count($array_options)>0) {
+ $line->array_options=$array_options;
}
$result=$line->insert($user);
diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php
index ee269646c84..7343e65c854 100644
--- a/htdocs/filefunc.inc.php
+++ b/htdocs/filefunc.inc.php
@@ -191,9 +191,10 @@ define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
*/
// Path to root libraries
if (! defined('ADODB_PATH')) { define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH))?DOL_DOCUMENT_ROOT.'/includes/adodbtime/':(empty($dolibarr_lib_ADODB_PATH)?'':$dolibarr_lib_ADODB_PATH.'/')); }
-if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdf/':$dolibarr_lib_TCPDF_PATH.'/'); }
if (! defined('FPDF_PATH')) { define('FPDF_PATH', (empty($dolibarr_lib_FPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/fpdf/':$dolibarr_lib_FPDF_PATH.'/'); } // Used only for package that can't include tcpdf
+if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdf/':$dolibarr_lib_TCPDF_PATH.'/'); }
if (! defined('FPDI_PATH')) { define('FPDI_PATH', (empty($dolibarr_lib_FPDI_PATH))?DOL_DOCUMENT_ROOT.'/includes/fpdfi/':$dolibarr_lib_FPDI_PATH.'/'); }
+if (! defined('TCPDI_PATH')) { define('TCPDI_PATH', (empty($dolibarr_lib_TCPDI_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdi/':$dolibarr_lib_TCPDI_PATH.'/'); }
if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH))?DOL_DOCUMENT_ROOT.'/includes/nusoap/lib/':(empty($dolibarr_lib_NUSOAP_PATH)?'':$dolibarr_lib_NUSOAP_PATH.'/')); }
if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH))?DOL_DOCUMENT_ROOT.'/includes/phpexcel/':(empty($dolibarr_lib_PHPEXCEL_PATH)?'':$dolibarr_lib_PHPEXCEL_PATH.'/')); }
if (! defined('GEOIP_PATH')) { define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH))?DOL_DOCUMENT_ROOT.'/includes/geoip/':(empty($dolibarr_lib_GEOIP_PATH)?'':$dolibarr_lib_GEOIP_PATH.'/')); }
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 08cf9d4bbf2..e626760f83e 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -214,13 +214,13 @@ class CommandeFournisseur extends CommonOrder
$sql.= " l.qty,";
$sql.= " l.tva_tx, l.remise_percent, l.subprice,";
$sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,";
- $sql.= " l.total_ht, l.total_tva, l.total_ttc,";
+ $sql.= " l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,";
$sql.= " l.date_start, l.date_end";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= " WHERE l.fk_commande = ".$this->id;
- $sql.= " ORDER BY l.rowid";
+ $sql.= " ORDER BY l.rang, l.rowid";
//print $sql;
dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG);
@@ -267,6 +267,11 @@ class CommandeFournisseur extends CommonOrder
$line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end);
+ $this->special_line = $objp->special_line;
+ $this->fk_parent_line = $objp->fk_parent_line;
+
+ $this->rang = $objp->rang;
+
$this->lines[$i] = $line;
$i++;
@@ -662,7 +667,7 @@ class CommandeFournisseur extends CommonOrder
if (! empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT))
{
$result=$this->add_contact($user->id, 'SALESREPFOLL', 'internal', 1);
- if ($result < 0)
+ if ($result < 0 && $result != -2) // -2 means already exists
{
$error++;
}
@@ -1044,7 +1049,9 @@ class CommandeFournisseur extends CommonOrder
$error=0;
- $this->db->begin();
+ $this->context['createfromclone'] = 'createfromclone';
+
+ $this->db->begin();
// Load source object
$objFrom = dol_clone($this);
@@ -1080,7 +1087,9 @@ class CommandeFournisseur extends CommonOrder
// End call triggers
}
- // End
+ unset($this->context['createfromclone']);
+
+ // End
if (! $error)
{
$this->db->commit();
@@ -1113,9 +1122,10 @@ class CommandeFournisseur extends CommonOrder
* @param bool $notrigger Disable triggers
* @param int $date_start Date start of service
* @param int $date_end Date end of service
+ * @param array $array_options extrafields array
* @return int <=0 if KO, >0 if OK
*/
- function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null)
+ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0)
{
global $langs,$mysoc;
@@ -1250,7 +1260,19 @@ class CommandeFournisseur extends CommonOrder
{
$this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande_fournisseurdet');
- if (! $notrigger)
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $linetmp = new CommandeFournisseurLigne($this->db);
+ $linetmp->id=$this->rowid;
+ $linetmp->array_options = $array_options;
+ $result=$linetmp->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error && ! $notrigger)
{
global $conf, $langs, $user;
// Call trigger
@@ -1389,51 +1411,53 @@ class CommandeFournisseur extends CommonOrder
*
* @param int $idline Id of line to delete
* @param int $notrigger 1=Disable call to triggers
- * @return >=0 if OK, <0 if KO
+ * @return <0 if KO, >0 if OK
*/
function deleteline($idline, $notrigger=0)
{
global $user,$langs,$conf;
- if ($this->statut == 0)
+
+ if ($this->statut != 0)
{
- $this->db->begin();
+ return -1;
+ }
- if (! $notrigger)
+ $this->db->begin();
+
+ if (! $notrigger)
+ {
+ // Call trigger
+ $result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user);
+ if ($result < 0) $error++;
+ // End call triggers
+ }
+
+ if (! $error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idline;
+ $resql=$this->db->query($sql);
+
+ dol_syslog(get_class($this)."::deleteline sql=".$sql);
+ if (! $resql)
{
- // Call trigger
- $result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user);
- if ($result < 0) $error++;
- // End call triggers
+ $this->error=$this->db->lasterror();
+ $error++;
}
+ }
- if (! $error)
- {
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idline;
- $resql=$this->db->query($sql);
+ if (! $error)
+ {
+ $result=$this->update_price();
+ }
- dol_syslog(get_class($this)."::deleteline sql=".$sql);
- if (! $resql)
- {
- $this->error=$this->db->lasterror();
- $error++;
- }
- }
-
- if (! $error)
- {
- $result=$this->update_price();
-
- $this->db->commit();
- return 0;
- }
- else
- {
- $this->db->rollback();
- return -1;
- }
+ if (! $error)
+ {
+ $this->db->commit();
+ return 1;
}
else
- {
+ {
+ $this->db->rollback();
return -1;
}
}
@@ -1755,23 +1779,24 @@ class CommandeFournisseur extends CommonOrder
/**
* Update line
*
- * @param int $rowid Id de la ligne de facture
- * @param string $desc Description de la ligne
- * @param double $pu Prix unitaire
- * @param double $qty Quantity
- * @param double $remise_percent Pourcentage de remise de la ligne
- * @param double $txtva Taux TVA
- * @param double $txlocaltax1 Localtax1 tax
- * @param double $txlocaltax2 Localtax2 tax
- * @param double $price_base_type Type of price base
- * @param int $info_bits Miscellaneous informations
- * @param int $type Type of line (0=product, 1=service)
- * @param int $notrigger Disable triggers
- * @param timestamp $date_start Date start of service
- * @param timestamp $date_end Date end of service
- * @return int < 0 if error, > 0 if ok
+ * @param int $rowid Id de la ligne de facture
+ * @param string $desc Description de la ligne
+ * @param double $pu Prix unitaire
+ * @param double $qty Quantity
+ * @param double $remise_percent Pourcentage de remise de la ligne
+ * @param double $txtva Taux TVA
+ * @param double $txlocaltax1 Localtax1 tax
+ * @param double $txlocaltax2 Localtax2 tax
+ * @param double $price_base_type Type of price base
+ * @param int $info_bits Miscellaneous informations
+ * @param int $type Type of line (0=product, 1=service)
+ * @param int $notrigger Disable triggers
+ * @param timestamp $date_start Date start of service
+ * @param timestamp $date_end Date end of service
+ * @param array $array_options extrafields array
+ * @return int < 0 if error, > 0 if ok
*/
- function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='')
+ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0)
{
global $mysoc;
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type");
@@ -1848,8 +1873,19 @@ class CommandeFournisseur extends CommonOrder
if ($result > 0)
{
$this->rowid = $rowid;
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $tmpline = new CommandeFournisseurLigne($this->db);
+ $tmpline->id=$this->rowid;
+ $tmpline->array_options = $array_options;
+ $result=$tmpline->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
- if (! $notrigger)
+ if (! $error && ! $notrigger)
{
global $conf, $langs, $user;
// Call trigger
@@ -1863,14 +1899,25 @@ class CommandeFournisseur extends CommonOrder
}
// Mise a jour info denormalisees au niveau facture
- $this->update_price('','auto');
+ if (! $error)
+ {
+ $this->update_price('','auto');
+ }
- $this->db->commit();
- return $result;
+ if (! $error)
+ {
+ $this->db->commit();
+ return $result;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
}
else
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
@@ -2138,17 +2185,22 @@ class CommandeFournisseur extends CommonOrder
*/
function getMaxDeliveryTimeDay($langs)
{
- if (empty($this->lines)) return $langs->trans('Undefined');
+ if (empty($this->lines)) return '';
+
+ $obj = new ProductFournisseur($this->db);
$nb = 0;
- foreach ($this->lines as $line) {
- $obj = new ProductFournisseur($this->db);
- $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
- if ($idp) {
- $obj->fetch($idp);
- if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
+ foreach ($this->lines as $line)
+ {
+ if ($line->fk_product > 0)
+ {
+ $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
+ if ($idp)
+ {
+ $obj->fetch($idp);
+ if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
+ }
}
-
}
if ($nb === 0) return $langs->trans('Undefined');
@@ -2163,6 +2215,14 @@ class CommandeFournisseur extends CommonOrder
*/
class CommandeFournisseurLigne extends CommonOrderLine
{
+ var $db;
+ var $error;
+
+ public $element='commande_fournisseurdet';
+ public $table_element='commande_fournisseurdet';
+
+ var $oldline;
+
// From llx_commandedet
var $qty;
var $tva_tx;
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index d7252d188db..8283f1cb957 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -450,7 +450,7 @@ class FactureFournisseur extends CommonInvoice
$result=$this->fetch_lines();
if ($result < 0)
{
- $this->error=$this->db->error();
+ $this->error=$this->db->lasterror();
return -3;
}
@@ -482,11 +482,12 @@ class FactureFournisseur extends CommonInvoice
{
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx, f.tva';
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
- $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits';
+ $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
$sql.= ' WHERE fk_facture_fourn='.$this->id;
+ $sql.= ' ORDER BY f.rang, f.rowid';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql_rows = $this->db->query($sql);
@@ -500,7 +501,9 @@ class FactureFournisseur extends CommonInvoice
{
$obj = $this->db->fetch_object($resql_rows);
- $this->lines[$i] = new stdClass();
+ $this->lines[$i] = new FactureFournisseurLigne($this->db);
+
+ $this->lines[$i]->id = $obj->rowid;
$this->lines[$i]->rowid = $obj->rowid;
$this->lines[$i]->description = $obj->description;
$this->lines[$i]->product_ref = $obj->product_ref; // Internal reference
@@ -523,7 +526,10 @@ class FactureFournisseur extends CommonInvoice
$this->lines[$i]->total_ttc = $obj->total_ttc;
$this->lines[$i]->fk_product = $obj->fk_product;
$this->lines[$i]->product_type = $obj->product_type;
- $this->lines[$i]->info_bits = $obj->info_bits;
+ $this->lines[$i]->info_bits = $obj->info_bits;
+ $this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
+ $this->lines[$i]->special_code = $obj->special_code;
+ $this->lines[$i]->rang = $obj->rang;
$i++;
}
@@ -1109,11 +1115,12 @@ class FactureFournisseur extends CommonInvoice
* @param int $type Type of line (0=product, 1=service)
* @param int $rang Position of line
* @param int $notrigger Disable triggers
+ * @param array $array_options extrafields array
* @return int >0 if OK, <0 if KO
*
* FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order.
*/
- function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false)
+ function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0)
{
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@@ -1150,7 +1157,7 @@ class FactureFournisseur extends CommonInvoice
{
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
- $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true);
+ $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options);
if ($result > 0)
{
$this->rowid = $idligne;
@@ -1189,22 +1196,25 @@ class FactureFournisseur extends CommonInvoice
/**
* Update a line detail into database
*
- * @param int $id Id of line invoice
- * @param string $desc Description of line
- * @param double $pu Prix unitaire (HT ou TTC selon price_base_type)
- * @param double $vatrate VAT Rate
- * @param double $txlocaltax1 LocalTax1 Rate
- * @param double $txlocaltax2 LocalTax2 Rate
- * @param double $qty Quantity
- * @param int $idproduct Id produit
- * @param double $price_base_type HT or TTC
- * @param int $info_bits Miscellaneous informations of line
- * @param int $type Type of line (0=product, 1=service)
- * @param double $remise_percent Pourcentage de remise de la ligne
- * @param int $notrigger Disable triggers
- * @return int <0 if KO, >0 if OK
+ * @param int $id Id of line invoice
+ * @param string $desc Description of line
+ * @param double $pu Prix unitaire (HT ou TTC selon price_base_type)
+ * @param double $vatrate VAT Rate
+ * @param double $txlocaltax1 LocalTax1 Rate
+ * @param double $txlocaltax2 LocalTax2 Rate
+ * @param double $qty Quantity
+ * @param int $idproduct Id produit
+ * @param double $price_base_type HT or TTC
+ * @param int $info_bits Miscellaneous informations of line
+ * @param int $type Type of line (0=product, 1=service)
+ * @param double $remise_percent Pourcentage de remise de la ligne
+ * @param int $notrigger Disable triggers
+ * @param timestamp $date_start Date start of service
+ * @param timestamp $date_end Date end of service
+ * @param array $array_options extrafields array
+ * @return int <0 if KO, >0 if OK
*/
- function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false)
+ function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0)
{
global $mysoc;
dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG);
@@ -1285,7 +1295,19 @@ class FactureFournisseur extends CommonInvoice
{
$this->rowid = $id;
- if (! $notrigger)
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $linetmp = new FactureFournisseurLigne($this->db);
+ $linetmp->id=$this->rowid;
+ $linetmp->array_options = $array_options;
+ $result=$linetmp->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+
+ if (! $error && ! $notrigger)
{
global $conf, $langs, $user;
// Call trigger
@@ -1301,9 +1323,16 @@ class FactureFournisseur extends CommonInvoice
// Update total price into invoice record
$result=$this->update_price('','auto');
- $this->db->commit();
-
- return $result;
+ if (! $error)
+ {
+ $this->db->commit();
+ return $result;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
}
else
{
@@ -1318,7 +1347,7 @@ class FactureFournisseur extends CommonInvoice
*
* @param int $rowid Id of line to delete
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
- * @return void
+ * @return int <0 if KO, >0 if OK
*/
function deleteline($rowid, $notrigger=0)
{
@@ -1356,7 +1385,7 @@ class FactureFournisseur extends CommonInvoice
if (! $error)
{
// Mise a jour prix facture
- $this->update_price();
+ $result=$this->update_price();
}
if (! $error)
@@ -1716,7 +1745,9 @@ class FactureFournisseur extends CommonInvoice
$object=new FactureFournisseur($this->db);
- $this->db->begin();
+ $object->context['createfromclone'] = 'createfromclone';
+
+ $this->db->begin();
// Load source object
$object->fetch($fromid);
@@ -1762,6 +1793,8 @@ class FactureFournisseur extends CommonInvoice
}
+ unset($object->context['createfromclone']);
+
// End
if (! $error)
{
@@ -1810,3 +1843,35 @@ class FactureFournisseur extends CommonInvoice
}
}
+
+
+
+/**
+ * Class to manage line invoices
+ */
+class FactureFournisseurLigne extends CommonInvoice
+{
+ var $db;
+ var $error;
+
+ var $pu_ht;
+ var $pu_ttc;
+
+ public $element='facture_fourn_det';
+ public $table_element='facture_fourn_det';
+
+ var $oldline;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ function __construct($db)
+ {
+ $this->db= $db;
+ }
+
+
+}
+
diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php
index 8e70461e5da..6fa617834c2 100755
--- a/htdocs/fourn/class/fournisseur.product.class.php
+++ b/htdocs/fourn/class/fournisseur.product.class.php
@@ -485,14 +485,20 @@ class ProductFournisseur extends Product
/**
* Load properties for minimum price
*
- * @param int $prodid Product id
- * @param int $qty Minimum quantity
- * @return int <0 if KO, >0 if OK
+ * @param int $prodid Product id
+ * @param int $qty Minimum quantity
+ * @return int <0 if KO, 0=Not found of no product id provided, >0 if OK
*/
function find_min_price_product_fournisseur($prodid, $qty=0)
{
global $conf;
+ if (empty($prodid))
+ {
+ dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
+ return 0;
+ }
+
$this->product_fourn_price_id = '';
$this->product_fourn_id = '';
$this->fourn_ref = '';
@@ -582,7 +588,7 @@ class ProductFournisseur extends Product
return 1;
}
else
- {
+ {
$this->error=$this->db->error();
return -1;
}
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index e6a5aafad38..68724345411 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -63,6 +63,8 @@ $confirm = GETPOST('confirm','alpha');
$comclientid = GETPOST('comid','int');
$socid = GETPOST('socid','int');
$projectid = GETPOST('projectid','int');
+$cancel = GETPOST('cancel','alpha');
+$lineid = GETPOST('lineid', 'int');
//PDF
$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@@ -107,6 +109,7 @@ else if (! empty($socid) && $socid > 0)
}
$permissionnote=$user->rights->fournisseur->commande->creer; // Used by the include of actions_setnotes.inc.php
+$permissiontoedit=$user->rights->fournisseur->commande->creer; // Used by the include of actions_lineupdown.inc.php
/*
@@ -117,1084 +120,1105 @@ $parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
-include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
-
-if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
+if (empty($reshook))
{
- $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
- if ($result < 0) dol_print_error($db, $object->error);
-}
+ if ($cancel) $action='';
-// conditions de reglement
-if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
-{
- $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
-}
+ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
-// mode de reglement
-if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
-{
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
-}
+ include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
-// bank account
-if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer)
-{
- $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
-}
-
-// date de livraison
-if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer)
-{
- $result=$object->set_date_livraison($user,$datelivraison);
- if ($result < 0)
+ if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
{
- setEventMessage($object->error, 'errors');
- }
-}
-
-// Set project
-if ($action == 'classin' && $user->rights->fournisseur->commande->creer)
-{
- $object->setProject($projectid);
-}
-
-if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
-{
- $result = $object->set_remise($user, $_POST['remise_percent']);
-}
-
-if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
-{
- if (in_array($object->statut, array(1, 2, 5, 6, 7, 9)))
- {
- if ($object->statut == 1) $newstatus=0; // Validated->Draft
- else if ($object->statut == 2) $newstatus=0; // Approved->Draft
- else if ($object->statut == 5) $newstatus=4; // Received->Received partially
- else if ($object->statut == 6) $newstatus=2; // Canceled->Approved
- else if ($object->statut == 7) $newstatus=3; // Canceled->Process running
- else if ($object->statut == 9) $newstatus=1; // Refused->Validated
-
- $result = $object->setStatus($user, $newstatus);
- if ($result > 0)
- {
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
- }
-}
-
-/*
- * Add a line into product
- */
-if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
-{
- $langs->load('errors');
- $error = 0;
-
- // Set if we used free entry or predefined product
- $predef='';
- $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
- $date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
- $date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
- if (GETPOST('prod_entry_mode') == 'free')
- {
- $idprod=0;
- $price_ht = GETPOST('price_ht');
- $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
- }
- else
- {
- $idprod=GETPOST('idprod', 'int');
- $price_ht = '';
- $tva_tx = '';
+ $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
+ if ($result < 0) dol_print_error($db, $object->error);
}
- $qty = GETPOST('qty'.$predef);
- $remise_percent=GETPOST('remise_percent'.$predef);
-
- if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
- {
- setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
- }
- if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('idprodfournprice') && GETPOST('type') < 0)
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
- $error++;
- }
- if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='') // Unit price can be 0 but not ''
- {
- setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
- $error++;
- }
- if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('dp_desc'))
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
- $error++;
- }
- if (! GETPOST('qty'))
- {
- setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
- $error++;
- }
-
- // Ecrase $pu par celui du produit
- // Ecrase $desc par celui du produit
- // Ecrase $txtva par celui du produit
- if ((GETPOST('prod_entry_mode') != 'free') && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
- {
- $idprod=0;
- $productsupplier = new ProductFournisseur($db);
-
- if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') $idprod=-2; // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -1)
-
- if (GETPOST('idprodfournprice') > 0)
- {
- $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat.
- }
-
- if ($idprod > 0)
- {
- $res=$productsupplier->fetch($idprod);
-
- $label = $productsupplier->libelle;
-
- $desc = $productsupplier->description;
- if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
-
- $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
- $type = $productsupplier->type;
-
- // Local Taxes
- $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
- $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
-
- $result=$object->addline(
- $desc,
- $productsupplier->fourn_pu,
- $qty,
- $tva_tx,
- $localtax1_tx,
- $localtax2_tx,
- $productsupplier->id,
- GETPOST('idprodfournprice'),
- $productsupplier->fourn_ref,
- $remise_percent,
- 'HT',
- $pu_ttc,
- $type,
- '',
- '',
- $date_start,
- $date_end
- );
- }
- if ($idprod == -2 || $idprod == 0)
- {
- // Product not selected
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ProductOrService")), 'errors');
- }
- if ($idprod == -1)
- {
- // Quantity too low
- $error++;
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors');
- }
- }
- else if((GETPOST('price_ht')!=='' || GETPOST('price_ttc')!=='') && empty($error))
+ // conditions de reglement
+ if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
{
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
- $tva_tx = str_replace('*', '', $tva_tx);
- $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
- $desc = $product_desc;
- $type = GETPOST('type');
+ $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
+ }
- $tva_tx = price2num($tva_tx); // When vat is text input field
+ // mode de reglement
+ if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
+ {
+ $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
+ }
- // Local Taxes
- $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
- $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
+ // bank account
+ if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer)
+ {
+ $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
+ }
- if (!empty($_POST['price_ht']))
+ // date de livraison
+ if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer)
+ {
+ $result=$object->set_date_livraison($user,$datelivraison);
+ if ($result < 0)
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+ // Set project
+ if ($action == 'classin' && $user->rights->fournisseur->commande->creer)
+ {
+ $object->setProject($projectid);
+ }
+
+ if ($action == 'setremisepercent' && $user->rights->fournisseur->commande->creer)
+ {
+ $result = $object->set_remise($user, $_POST['remise_percent']);
+ }
+
+ if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
+ {
+ if (in_array($object->statut, array(1, 2, 5, 6, 7, 9)))
+ {
+ if ($object->statut == 1) $newstatus=0; // Validated->Draft
+ else if ($object->statut == 2) $newstatus=0; // Approved->Draft
+ else if ($object->statut == 5) $newstatus=4; // Received->Received partially
+ else if ($object->statut == 6) $newstatus=2; // Canceled->Approved
+ else if ($object->statut == 7) $newstatus=3; // Canceled->Process running
+ else if ($object->statut == 9) $newstatus=1; // Refused->Validated
+
+ $result = $object->setStatus($user, $newstatus);
+ if ($result > 0)
+ {
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+ }
+
+ /*
+ * Add a line into product
+ */
+ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
+ {
+ $langs->load('errors');
+ $error = 0;
+
+ // Set if we used free entry or predefined product
+ $predef='';
+ $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
+ $date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
+ $date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
+ if (GETPOST('prod_entry_mode') == 'free')
+ {
+ $idprod=0;
+ $price_ht = GETPOST('price_ht');
+ $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
+ }
+ else
+ {
+ $idprod=GETPOST('idprod', 'int');
+ $price_ht = '';
+ $tva_tx = '';
+ }
+
+ $qty = GETPOST('qty'.$predef);
+ $remise_percent=GETPOST('remise_percent'.$predef);
+
+ // Extrafields
+ $extrafieldsline = new ExtraFields($db);
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
+ // Unset extrafield
+ if (is_array($extralabelsline)) {
+ // Get extra fields
+ foreach ($extralabelsline as $key => $value) {
+ unset($_POST["options_" . $key]);
+ }
+ }
+
+ if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht') < 0 && $qty < 0)
+ {
+ setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('idprodfournprice') && GETPOST('type') < 0)
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && GETPOST('price_ht')==='' && GETPOST('price_ttc')==='') // Unit price can be 0 but not ''
+ {
+ setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
+ $error++;
+ }
+ if (GETPOST('prod_entry_mode')=='free' && ! GETPOST('dp_desc'))
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
+ $error++;
+ }
+ if (! GETPOST('qty'))
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
+ $error++;
+ }
+
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ if ((GETPOST('prod_entry_mode') != 'free') && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
+ {
+ $idprod=0;
+ $productsupplier = new ProductFournisseur($db);
+
+ if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') $idprod=-2; // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -1)
+
+ if (GETPOST('idprodfournprice') > 0)
+ {
+ $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat.
+ }
+
+ if ($idprod > 0)
+ {
+ $res=$productsupplier->fetch($idprod);
+
+ $label = $productsupplier->libelle;
+
+ $desc = $productsupplier->description;
+ if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
+
+ $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice'));
+ $type = $productsupplier->type;
+
+ // Local Taxes
+ $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
+ $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
+
+ $result=$object->addline(
+ $desc,
+ $productsupplier->fourn_pu,
+ $qty,
+ $tva_tx,
+ $localtax1_tx,
+ $localtax2_tx,
+ $productsupplier->id,
+ GETPOST('idprodfournprice'),
+ $productsupplier->fourn_ref,
+ $remise_percent,
+ 'HT',
+ $pu_ttc,
+ $type,
+ '',
+ '',
+ $date_start,
+ $date_end,
+ $array_options
+ );
+ }
+ if ($idprod == -2 || $idprod == 0)
+ {
+ // Product not selected
+ $error++;
+ $langs->load("errors");
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ProductOrService")), 'errors');
+ }
+ if ($idprod == -1)
+ {
+ // Quantity too low
+ $error++;
+ $langs->load("errors");
+ setEventMessage($langs->trans("ErrorQtyTooLowForThisSupplier"), 'errors');
+ }
+ }
+ else if((GETPOST('price_ht')!=='' || GETPOST('price_ttc')!=='') && empty($error))
+ {
+ $pu_ht = price2num($price_ht, 'MU');
+ $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
+ $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
+ $tva_tx = str_replace('*', '', $tva_tx);
+ $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
+ $desc = $product_desc;
+ $type = GETPOST('type');
+
+ $tva_tx = price2num($tva_tx); // When vat is text input field
+
+ // Local Taxes
+ $localtax1_tx= get_localtax($tva_tx, 1,$mysoc,$object->thirdparty);
+ $localtax2_tx= get_localtax($tva_tx, 2,$mysoc,$object->thirdparty);
+
+ if (GETPOST('price_ht')!=='')
+ {
+ $price_base_type = 'HT';
+ $ht = price2num(GETPOST('price_ht'));
+ $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end, $array_options);
+ }
+ else
+ {
+ $ttc = price2num(GETPOST('price_ttc'));
+ $ht = $ttc / (1 + ($tva_tx / 100));
+ $price_base_type = 'HT';
+ $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options);
+ }
+ }
+
+ //print "xx".$tva_tx; exit;
+ if (! $error && $result > 0)
+ {
+ $ret=$object->fetch($object->id); // Reload to get new records
+
+ // Define output language
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ {
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $model=$object->modelpdf;
+ $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);
+ }
+
+ unset($_POST ['prod_entry_mode']);
+
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['remise_percent']);
+ unset($_POST['pu']);
+ unset($_POST['price_ht']);
+ unset($_POST['price_ttc']);
+ unset($_POST['tva_tx']);
+ unset($_POST['label']);
+ unset($localtax1_tx);
+ unset($localtax2_tx);
+ unset($_POST['np_marginRate']);
+ unset($_POST['np_markRate']);
+ unset($_POST['dp_desc']);
+ unset($_POST['idprodfournprice']);
+
+ unset($_POST['date_starthour']);
+ unset($_POST['date_startmin']);
+ unset($_POST['date_startsec']);
+ unset($_POST['date_startday']);
+ unset($_POST['date_startmonth']);
+ unset($_POST['date_startyear']);
+ unset($_POST['date_endhour']);
+ unset($_POST['date_endmin']);
+ unset($_POST['date_endsec']);
+ unset($_POST['date_endday']);
+ unset($_POST['date_endmonth']);
+ unset($_POST['date_endyear']);
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+ /*
+ * Mise a jour d'une ligne dans la commande
+ */
+ if ($action == 'updateline' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
+ {
+ $tva_tx = GETPOST('tva_tx');
+
+ if (GETPOST('price_ht') != '')
{
$price_base_type = 'HT';
- $ht = price2num($_POST['price_ht']);
+ $ht = price2num(GETPOST('price_ht'));
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end);
}
else
{
- $ttc = price2num($_POST['price_ttc']);
- $ht = $ttc / (1 + ($tauxtva / 100));
+ $ttc = price2num(GETPOST('price_ttc'));
+ $ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end);
}
- }
- //print "xx".$tva_tx; exit;
- if (! $error && $result > 0)
- {
- $ret=$object->fetch($object->id); // Reload to get new records
+ if ($lineid)
+ {
+ $line = new CommandeFournisseurLigne($db);
+ $res = $line->fetch($lineid);
+ if (!$res) dol_print_error($db);
+ }
- // Define output language
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $model=$object->modelpdf;
- $ret = $object->fetch($id); // Reload to get new records
+ $date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
+ $date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
- $result=$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result < 0) dol_print_error($db,$result);
- }
+ $localtax1_tx=get_localtax($tva_tx,1,$mysoc,$object->thirdparty);
+ $localtax2_tx=get_localtax($tva_tx,2,$mysoc,$object->thirdparty);
- unset($_POST ['prod_entry_mode']);
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['remise_percent']);
- unset($_POST['pu']);
- unset($_POST['price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['label']);
- unset($localtax1_tx);
- unset($localtax2_tx);
- unset($_POST['np_marginRate']);
- unset($_POST['np_markRate']);
- unset($_POST['dp_desc']);
- unset($_POST['idprodfournprice']);
-
- unset($_POST['date_starthour']);
- unset($_POST['date_startmin']);
- unset($_POST['date_startsec']);
- unset($_POST['date_startday']);
- unset($_POST['date_startmonth']);
- unset($_POST['date_startyear']);
- unset($_POST['date_endhour']);
- unset($_POST['date_endmin']);
- unset($_POST['date_endsec']);
- unset($_POST['date_endday']);
- unset($_POST['date_endmonth']);
- unset($_POST['date_endyear']);
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
-}
-
-/*
- * Mise a jour d'une ligne dans la commande
- */
-if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel'))
-{
- if ($_POST["elrowid"])
- {
- $line = new CommandeFournisseurLigne($db);
- $res = $line->fetch($_POST["elrowid"]);
- if (!$res) dol_print_error($db);
- }
-
- $date_start=dol_mktime(GETPOST('date_start'.$date_pf.'hour'), GETPOST('date_start'.$date_pf.'min'), 0, GETPOST('date_start'.$date_pf.'month'), GETPOST('date_start'.$date_pf.'day'), GETPOST('date_start'.$date_pf.'year'));
- $date_end=dol_mktime(GETPOST('date_end'.$date_pf.'hour'), GETPOST('date_end'.$date_pf.'min'), 0, GETPOST('date_end'.$date_pf.'month'), GETPOST('date_end'.$date_pf.'day'), GETPOST('date_end'.$date_pf.'year'));
-
- $localtax1_tx=get_localtax($_POST['tva_tx'],1,$mysoc,$object->thirdparty);
- $localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty);
-
- $result = $object->updateline(
- $_POST['elrowid'],
- $_POST['eldesc'],
- $_POST['pu'],
- $_POST['qty'],
- $_POST['remise_percent'],
- $_POST['tva_tx'],
- $localtax1_tx,
- $localtax2_tx,
- 'HT',
- 0,
- isset($_POST["type"])?$_POST["type"]:$line->product_type,
- false,
- $date_start,
- $date_end
- );
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['idprodfournprice']);
- unset($_POST['remmise_percent']);
- unset($_POST['dp_desc']);
- unset($_POST['np_desc']);
- unset($_POST['pu']);
- unset($_POST['tva_tx']);
- unset($_POST['date_start']);
- unset($_POST['date_end']);
- unset($localtax1_tx);
- unset($localtax2_tx);
-
- if ($result >= 0)
- {
- // Define output language
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $model=$object->modelpdf;
- $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);
- }
- }
- else
- {
- dol_print_error($db,$object->error);
- exit;
- }
-}
-
-if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
-{
-
- $result = $object->deleteline(GETPOST('lineid'));
- if ($result >= 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $ret=$object->fetch($object->id); // Reload to get new records
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- }
- else
- {
- $error++;
- setEventMessage($object->error, 'errors');
- }
-
- if (! $error)
- {
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
-}
-
-if ($action == 'confirm_valid' && $confirm == 'yes' &&
- ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer))
- || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate)))
- )
-{
- $object->date_commande=dol_now();
- $result = $object->valid($user);
- if ($result >= 0)
- {
- // Define output language
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $model=$object->modelpdf;
- $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);
- }
- }
- else
- {
- setEventMessages($object->error, $object->errors, 'errors');
- }
-
- // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
- if ($user->rights->fournisseur->commande->approuver && ! (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
- {
- $action='confirm_approve';
- }
-}
-
-if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
-{
- $idwarehouse=GETPOST('idwarehouse', 'int');
-
- $qualified_for_stock_change=0;
- if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(2);
- }
- else
- {
- $qualified_for_stock_change=$object->hasProductsOrServices(1);
- }
-
- // Check parameters
- if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
- {
- if (! $idwarehouse || $idwarehouse == -1)
- {
- $error++;
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")), 'errors');
- $action='';
- }
- }
-
- if (! $error)
- {
- $result = $object->approve($user, $idwarehouse);
- if ($result > 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
- }
-}
-
-if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
-{
- $result = $object->refuse($user);
- if ($result > 0)
- {
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
-}
-
-if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
-{
- $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
- if ($result > 0)
- {
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
-}
-
-
-if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
-{
- $result=$object->delete($user);
- if ($result > 0)
- {
- header("Location: ".DOL_URL_ROOT.'/fourn/commande/list.php');
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
-}
-
-// Action clone object
-if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
-{
- if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
- {
- setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
- }
- else
- {
- if ($object->id > 0)
- {
- $result=$object->createFromClone();
- if ($result > 0)
- {
- header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- $action='';
+ // Extrafields Lines
+ $extrafieldsline = new ExtraFields($db);
+ $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
+ $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
+ // Unset extrafield POST Data
+ if (is_array($extralabelsline)) {
+ foreach ($extralabelsline as $key => $value) {
+ unset($_POST["options_" . $key]);
}
}
+
+ $result = $object->updateline(
+ $lineid,
+ $_POST['product_desc'],
+ $ht,
+ $_POST['qty'],
+ $_POST['remise_percent'],
+ $tva_tx,
+ $localtax1_tx,
+ $localtax2_tx,
+ $price_base_type,
+ 0,
+ isset($_POST["type"])?$_POST["type"]:$line->product_type,
+ false,
+ $date_start,
+ $date_end,
+ $array_options
+ );
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['idprodfournprice']);
+ unset($_POST['remmise_percent']);
+ unset($_POST['dp_desc']);
+ unset($_POST['np_desc']);
+ unset($_POST['pu']);
+ unset($_POST['tva_tx']);
+ unset($_POST['date_start']);
+ unset($_POST['date_end']);
+ unset($localtax1_tx);
+ unset($localtax2_tx);
+
+ if ($result >= 0)
+ {
+ // Define output language
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ {
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $model=$object->modelpdf;
+ $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);
+ }
+ }
+ else
+ {
+ dol_print_error($db,$object->error);
+ exit;
+ }
}
-}
-// Receive
-if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
-{
-
- if ($_POST["type"])
- {
- $date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
-
- $result = $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]);
- if ($result > 0)
- {
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
- else if($result == -3)
- {
- setEventMessage($langs->trans("NotAuthorized"), 'errors');
- }
- else
- {
- dol_print_error($db,$object->error);
- exit;
- }
- }
- else
- {
- setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")), 'errors');
- }
-}
-
-if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
-{
- $result = $object->cancel($user);
- if ($result > 0)
- {
- header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
- exit;
- }
- else
- {
- setEventMessage($object->error, 'errors');
- }
-}
-
-// Line ordering
-if ($action == 'up' && $user->rights->fournisseur->commande->creer)
-{
- $object->line_up($_GET['rowid']);
-
- $outputlangs = $langs;
- if (! empty($_REQUEST['lang_id']))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
- exit;
-}
-if ($action == 'down' && $user->rights->fournisseur->commande->creer)
-{
- $object->line_down($_GET['rowid']);
-
- $outputlangs = $langs;
- if (! empty($_REQUEST['lang_id']))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($_REQUEST['lang_id']);
- }
- if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
- exit;
-}
-
-if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
-{
- // Build document
-
- // Save last template used to generate document
- if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
-
- $outputlangs = $langs;
- if (GETPOST('lang_id'))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang(GETPOST('lang_id'));
- }
- $result= $object->generateDocument($object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
-}
-
-// Delete file in doc form
-if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer)
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $langs->load("other");
- $upload_dir = $conf->fournisseur->commande->dir_output;
- $file = $upload_dir . '/' . GETPOST('file');
- $ret=dol_delete_file($file,0,0,0,$object);
- if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
- else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
-}
-
-if ($action == 'update_extras')
-{
- // Fill array 'array_options' with data from add form
- $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
- if ($ret < 0) $error++;
-
- if (!$error)
+ // Remove a product line
+ if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
{
- // Actions on extra fields (by external module or standard code)
- // FIXME le hook fait double emploi avec le trigger !!
- $hookmanager->initHooks(array('supplierorderdao'));
- $parameters=array('id'=>$object->id);
-
- $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
-
- if (empty($reshook))
+ $result = $object->deleteline($lineid);
+ if ($result > 0)
{
- if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
- {
- $result=$object->insertExtraFields();
-
- if ($result < 0)
- {
- $error++;
- }
-
+ // Define output language
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
+ $newlang = GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang))
+ $newlang = $object->thirdparty->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $ret = $object->fetch($object->id); // Reload to get new records
+ $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
- }
- else if ($reshook < 0) $error++;
- }
- else
- {
- $action = 'edit_extras';
- }
-}
-/*
- * Create an order
- */
-if ($action == 'add' && $user->rights->fournisseur->commande->creer)
-{
- $error=0;
-
- if ($socid <1)
- {
- setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('Supplier')), 'errors');
- $action='create';
- $error++;
- }
-
- if (! $error)
- {
- $db->begin();
-
- // Creation commande
- $object->ref_supplier = GETPOST('refsupplier');
- $object->socid = $socid;
- $object->cond_reglement_id = GETPOST('cond_reglement_id');
- $object->mode_reglement_id = GETPOST('mode_reglement_id');
- $object->fk_account = GETPOST('fk_account', 'int');
- $object->note_private = GETPOST('note_private');
- $object->note_public = GETPOST('note_public');
- $object->date_livraison = $datelivraison;
-
- // Fill array 'array_options' with data from add form
- $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-
- $id = $object->create($user);
- if ($id < 0)
- {
- $error++;
- }
-
- if ($error)
- {
- $langs->load("errors");
- $db->rollback();
- setEventMessage($langs->trans($object->error), 'errors');
- $action='create';
- $_GET['socid']=$_POST['socid'];
- }
- else
- {
- $db->commit();
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
- exit;
- }
- }
-}
-
-/*
- * Add file in email form
- */
-if (GETPOST('addfile'))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
- // Set tmp user directory TODO Use a dedicated directory for temp mails files
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
- dol_add_file_process($upload_dir_tmp,0,0);
- $action='presend';
-}
-
-/*
- * Remove file in email form
- */
-if (GETPOST('removedfile'))
-{
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
-
- // Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir_tmp = $vardir.'/temp';
-
- // TODO Delete only files that was uploaded from email form
- dol_remove_file_process($_POST['removedfile'],0);
- $action='presend';
-}
-
-/*
- * Send mail
- */
-if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
-{
- $langs->load('mails');
-
- if ($object->id > 0)
- {
-// $ref = dol_sanitizeFileName($object->ref);
-// $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
-
-// if (is_readable($file))
-// {
- if (GETPOST('sendto','alpha'))
- {
- // Le destinataire a ete fourni via le champ libre
- $sendto = GETPOST('sendto','alpha');
- $sendtoid = 0;
- }
- elseif (GETPOST('receiver','alpha') != '-1')
- {
- // Recipient was provided from combo list
- if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
- {
- $sendto = $object->client->email;
- $sendtoid = 0;
- }
- else // Id du contact
- {
- $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
- $sendtoid = GETPOST('receiver','alpha');
- }
- }
-
- if (dol_strlen($sendto))
- {
- $langs->load("commercial");
-
- $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
- $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
- $message = GETPOST('message');
- $sendtocc = GETPOST('sendtocc','alpha');
- $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
-
- if ($action == 'send')
- {
- if (dol_strlen(GETPOST('subject'))) $subject=GETPOST('subject');
- else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
- $actiontypecode='AC_SUP_ORD';
- $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
- if ($message)
- {
- if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
- $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
- $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
- $actionmsg = dol_concatdesc($actionmsg, $message);
- }
- $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
- }
-
- // Create form object
- include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
- $formmail = new FormMail($db);
-
- $attachedfiles=$formmail->get_attached_files();
- $filepath = $attachedfiles['paths'];
- $filename = $attachedfiles['names'];
- $mimetype = $attachedfiles['mimes'];
-
- // Send mail
- require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
- if ($mailfile->error)
- {
- setEventMessage($mailfile->error, 'errors');
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
- setEventMessage($mesg);
-
- $error=0;
-
- // Initialisation donnees
- $object->sendtoid = $sendtoid;
- $object->actiontypecode = $actiontypecode;
- $object->actionmsg = $actionmsg;
- $object->actionmsg2 = $actionmsg2;
- $object->fk_element = $object->id;
- $object->elementtype = $object->element;
-
- // Appel des triggers
- include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
- $interface=new Interfaces($db);
- $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
- if ($result < 0) { $error++; $errors=$interface->errors; }
- // Fin appel triggers
-
- if ($error)
- {
- setEventMessage($object->error, 'errors');
- }
- else
- {
- // Redirect here
- // This avoid sending mail twice if going out and then back to page
- header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
- exit;
- }
- }
- else
- {
- $langs->load("other");
- if ($mailfile->error)
- {
- $mesg = $langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.= ' '.$mailfile->error;
- }
- else
- {
- $mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
- }
-
- setEventMessage($mesg, 'errors');
- }
- }
-/* }
- else
- {
- $langs->load("other");
- $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').' !
';
- $action='presend';
- dol_syslog('Recipient email is empty');
- }*/
- }
- else
- {
- $langs->load("errors");
- setEventMessage($langs->trans('ErrorCantReadFile',$file), 'errors');
- dol_syslog('Failed to read file: '.$file);
- }
- }
- else
- {
- $langs->load("other");
- setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors');
- dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
- }
-}
-
-if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel'))
-{
- $ws_url = $object->thirdparty->webservices_url;
- $ws_key = $object->thirdparty->webservices_key;
- $ws_user = GETPOST('ws_user','alpha');
- $ws_password = GETPOST('ws_password','alpha');
- $ws_entity = GETPOST('ws_entity','int');
- $ws_thirdparty = GETPOST('ws_thirdparty','int');
-
- // NS and Authentication parameters
- $ws_ns='http://www.dolibarr.org/ns/';
- $ws_authentication=array(
- 'dolibarrkey'=>$ws_key,
- 'sourceapplication'=>'DolibarrWebServiceClient',
- 'login'=>$ws_user,
- 'password'=>$ws_password,
- 'entity'=>$ws_entity
- );
-
- //Is sync supplier web services module activated? and everything filled?
- if (empty($conf->syncsupplierwebservices->enabled)) {
- setEventMessage($langs->trans("WarningModuleNotActive",$langs->transnoentities("Module2650Name")));
- } else if (empty($ws_url) || empty($ws_key)) {
- setEventMessage($langs->trans("ErrorWebServicesFieldsRequired"), 'errors');
- } else if (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
- setEventMessage($langs->trans("ErrorFieldsRequired"), 'errors');
- }
- else
- {
- //Create SOAP client and connect it to order
- $soapclient_order = new nusoap_client($ws_url."/webservices/server_order.php");
- $soapclient_order->soap_defencoding='UTF-8';
- $soapclient_order->decodeUTF8(false);
-
- //Create SOAP client and connect it to product/service
- $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
- $soapclient_product->soap_defencoding='UTF-8';
- $soapclient_product->decodeUTF8(false);
-
- //Prepare the order lines from order
- $order_lines = array();
- foreach ($object->lines as $line)
- {
- $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $line->ref_supplier);
- $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
-
- if ($result_product["result"]["result_code"] == "OK")
- {
- $order_lines[] = array(
- 'desc' => $line->product_desc,
- 'type' => $line->product_type,
- 'product_id' => $result_product["product"]["id"],
- 'vat_rate' => $line->tva_tx,
- 'qty' => $line->qty,
- 'price' => $line->price,
- 'unitprice' => $line->subprice,
- 'total_net' => $line->total_ht,
- 'total_vat' => $line->total_tva,
- 'total' => $line->total_ttc,
- 'date_start' => $line->date_start,
- 'date_end' => $line->date_end,
- );
- }
- }
-
- //Prepare the order header
- $order = array(
- 'thirdparty_id' => $ws_thirdparty,
- 'date' => dol_print_date(dol_now(),'dayrfc'),
- 'total_net' => $object->total_ht,
- 'total_var' => $object->total_tva,
- 'total' => $object->total_ttc,
- 'lines' => $order_lines
- );
-
- $ws_parameters = array('authentication'=>$ws_authentication, 'order' => $order);
- $result_order = $soapclient_order->call("createOrder", $ws_parameters, $ws_ns, '');
-
- if (empty($result_order["result"]["result_code"])) //No result, check error str
- {
- setEventMessage($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", 'errors');
- }
- else if ($result_order["result"]["result_code"] != "OK") //Something went wrong
- {
- setEventMessage($langs->trans("SOAPError")." '".$result_order["result"]["result_code"]."' - '".$result_order["result"]["result_label"]."'", 'errors');
- }
- else
- {
- setEventMessage($langs->trans("RemoteOrderRef")." ".$result_order["ref"], 'mesgs');
- }
- }
-}
-
-if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer)
-{
- if ($action == 'addcontact')
- {
- if ($object->id > 0)
- {
- $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
- $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
- }
-
- if ($result >= 0)
- {
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
exit;
}
else
{
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ setEventMessages($object->error, $object->errors, 'errors');
+ /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */
+ $action='';
+ }
+ }
+
+ if ($action == 'confirm_valid' && $confirm == 'yes' &&
+ ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->commande->creer))
+ || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->fournisseur->supplier_order_advance->validate)))
+ )
+ {
+ $object->date_commande=dol_now();
+ $result = $object->valid($user);
+ if ($result >= 0)
+ {
+ // Define output language
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
+ {
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $model=$object->modelpdf;
+ $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);
+ }
+ }
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+
+ // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
+ if ($user->rights->fournisseur->commande->approuver && ! (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
+ {
+ $action='confirm_approve';
+ }
+ }
+
+ if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
+ {
+ $idwarehouse=GETPOST('idwarehouse', 'int');
+
+ $qualified_for_stock_change=0;
+ if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
+ {
+ $qualified_for_stock_change=$object->hasProductsOrServices(2);
+ }
+ else
+ {
+ $qualified_for_stock_change=$object->hasProductsOrServices(1);
+ }
+
+ // Check parameters
+ if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change)
+ {
+ if (! $idwarehouse || $idwarehouse == -1)
+ {
+ $error++;
+ setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")), 'errors');
+ $action='';
+ }
+ }
+
+ if (! $error)
+ {
+ $result = $object->approve($user, $idwarehouse);
+ if ($result > 0)
+ {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
+ if (! empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ }
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+ }
+
+ if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
+ {
+ $result = $object->refuse($user);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+ if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
+ {
+ $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']);
+ if ($result > 0)
+ {
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
+ }
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+
+ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
+ {
+ $result=$object->delete($user);
+ if ($result > 0)
+ {
+ header("Location: ".DOL_URL_ROOT.'/fourn/commande/list.php');
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+ // Action clone object
+ if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
+ {
+ if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
+ {
+ setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
+ }
+ else
+ {
+ if ($object->id > 0)
{
- $langs->load("errors");
- setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
+ $result=$object->createFromClone();
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ $action='';
+ }
+ }
+ }
+ }
+
+ // Receive
+ if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
+ {
+
+ if ($_POST["type"])
+ {
+ $date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
+
+ $result = $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
+ exit;
+ }
+ else if($result == -3)
+ {
+ setEventMessage($langs->trans("NotAuthorized"), 'errors');
+ }
+ else
+ {
+ dol_print_error($db,$object->error);
+ exit;
+ }
+ }
+ else
+ {
+ setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")), 'errors');
+ }
+ }
+
+ if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->fournisseur->commande->commander)
+ {
+ $result = $object->cancel($user);
+ if ($result > 0)
+ {
+ header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id);
+ exit;
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ }
+
+ if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) // En get ou en post
+ {
+ // Build document
+
+ // Save last template used to generate document
+ if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha'));
+
+ $outputlangs = $langs;
+ if (GETPOST('lang_id'))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang(GETPOST('lang_id'));
+ }
+ $result= $object->generateDocument($object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ }
+
+ // Delete file in doc form
+ if ($action == 'remove_file' && $object->id > 0 && $user->rights->fournisseur->commande->creer)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ $langs->load("other");
+ $upload_dir = $conf->fournisseur->commande->dir_output;
+ $file = $upload_dir . '/' . GETPOST('file');
+ $ret=dol_delete_file($file,0,0,0,$object);
+ if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
+ else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
+ }
+
+ if ($action == 'update_extras')
+ {
+ // Fill array 'array_options' with data from add form
+ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
+ if ($ret < 0) $error++;
+
+ if (! $error)
+ {
+ // Actions on extra fields (by external module or standard code)
+ // FIXME le hook fait double emploi avec le trigger !!
+ $hookmanager->initHooks(array('supplierorderdao'));
+ $parameters=array('id'=>$object->id);
+
+ $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
+
+ if (empty($reshook))
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$object->insertExtraFields();
+
+ if ($result < 0)
+ {
+ $error++;
+ }
+
+ }
+ }
+ else if ($reshook < 0) $error++;
+ }
+ else
+ {
+ $action = 'edit_extras';
+ }
+ }
+
+ /*
+ * Create an order
+ */
+ if ($action == 'add' && $user->rights->fournisseur->commande->creer)
+ {
+ $error=0;
+
+ if ($socid <1)
+ {
+ setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('Supplier')), 'errors');
+ $action='create';
+ $error++;
+ }
+
+ if (! $error)
+ {
+ $db->begin();
+
+ // Creation commande
+ $object->ref_supplier = GETPOST('refsupplier');
+ $object->socid = $socid;
+ $object->cond_reglement_id = GETPOST('cond_reglement_id');
+ $object->mode_reglement_id = GETPOST('mode_reglement_id');
+ $object->fk_account = GETPOST('fk_account', 'int');
+ $object->note_private = GETPOST('note_private');
+ $object->note_public = GETPOST('note_public');
+ $object->date_livraison = $datelivraison;
+
+ // Fill array 'array_options' with data from add form
+ if (! $error)
+ {
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+ if ($ret < 0) $error++;
+ }
+
+ if (! $error)
+ {
+ $id = $object->create($user);
+ if ($id < 0)
+ {
+ $error++;
+ setEventMessage($langs->trans($object->error), 'errors');
+ }
+ }
+
+ if ($error)
+ {
+ $langs->load("errors");
+ $db->rollback();
+ $action='create';
+ $_GET['socid']=$_POST['socid'];
+ }
+ else
+ {
+ $db->commit();
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
+ exit;
+ }
+ }
+ }
+
+ /*
+ * Add file in email form
+ */
+ if (GETPOST('addfile'))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir_tmp = $vardir.'/temp';
+
+ dol_add_file_process($upload_dir_tmp,0,0);
+ $action='presend';
+ }
+
+ /*
+ * Remove file in email form
+ */
+ if (GETPOST('removedfile'))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ // Set tmp user directory
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir_tmp = $vardir.'/temp';
+
+ // TODO Delete only files that was uploaded from email form
+ dol_remove_file_process($_POST['removedfile'],0);
+ $action='presend';
+ }
+
+ /*
+ * Send mail
+ */
+ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
+ {
+ $langs->load('mails');
+
+ if ($object->id > 0)
+ {
+ // $ref = dol_sanitizeFileName($object->ref);
+ // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+
+ // if (is_readable($file))
+ // {
+ if (GETPOST('sendto','alpha'))
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = GETPOST('sendto','alpha');
+ $sendtoid = 0;
+ }
+ elseif (GETPOST('receiver','alpha') != '-1')
+ {
+ // Recipient was provided from combo list
+ if (GETPOST('receiver','alpha') == 'thirdparty') // Id of third party
+ {
+ $sendto = $object->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $object->client->contact_get_property(GETPOST('receiver','alpha'),'email');
+ $sendtoid = GETPOST('receiver','alpha');
+ }
+ }
+
+ if (dol_strlen($sendto))
+ {
+ $langs->load("commercial");
+
+ $from = GETPOST('fromname','alpha') . ' <' . GETPOST('frommail','alpha') .'>';
+ $replyto = GETPOST('replytoname','alpha'). ' <' . GETPOST('replytomail','alpha').'>';
+ $message = GETPOST('message');
+ $sendtocc = GETPOST('sendtocc','alpha');
+ $deliveryreceipt = GETPOST('deliveryreceipt','alpha');
+
+ if ($action == 'send')
+ {
+ if (dol_strlen(GETPOST('subject'))) $subject=GETPOST('subject');
+ else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
+ $actiontypecode='AC_SUP_ORD';
+ $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
+ if ($message)
+ {
+ if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
+ $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
+ $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
+ $actionmsg = dol_concatdesc($actionmsg, $message);
+ }
+ $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
+ }
+
+ // Create form object
+ include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
+ $formmail = new FormMail($db);
+
+ $attachedfiles=$formmail->get_attached_files();
+ $filepath = $attachedfiles['paths'];
+ $filename = $attachedfiles['names'];
+ $mimetype = $attachedfiles['mimes'];
+
+ // Send mail
+ require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
+ if ($mailfile->error)
+ {
+ setEventMessage($mailfile->error, 'errors');
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
+ setEventMessage($mesg);
+
+ $error=0;
+
+ // Initialisation donnees
+ $object->sendtoid = $sendtoid;
+ $object->actiontypecode = $actiontypecode;
+ $object->actionmsg = $actionmsg;
+ $object->actionmsg2 = $actionmsg2;
+ $object->fk_element = $object->id;
+ $object->elementtype = $object->element;
+
+ // Appel des triggers
+ include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
+ if ($result < 0) { $error++; $errors=$interface->errors; }
+ // Fin appel triggers
+
+ if ($error)
+ {
+ setEventMessage($object->error, 'errors');
+ }
+ else
+ {
+ // Redirect here
+ // This avoid sending mail twice if going out and then back to page
+ header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ if ($mailfile->error)
+ {
+ $mesg = $langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.= ' '.$mailfile->error;
+ }
+ else
+ {
+ $mesg = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
+ }
+
+ setEventMessage($mesg, 'errors');
+ }
+ }
+ /* }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorMailRecipientIsEmpty').' !
';
+ $action='presend';
+ dol_syslog('Recipient email is empty');
+ }*/
+ }
+ else
+ {
+ $langs->load("errors");
+ setEventMessage($langs->trans('ErrorCantReadFile',$file), 'errors');
+ dol_syslog('Failed to read file: '.$file);
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")), 'errors');
+ dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
+ }
+ }
+
+ if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && ! GETPOST('cancel'))
+ {
+ $ws_url = $object->thirdparty->webservices_url;
+ $ws_key = $object->thirdparty->webservices_key;
+ $ws_user = GETPOST('ws_user','alpha');
+ $ws_password = GETPOST('ws_password','alpha');
+ $ws_entity = GETPOST('ws_entity','int');
+ $ws_thirdparty = GETPOST('ws_thirdparty','int');
+
+ // NS and Authentication parameters
+ $ws_ns='http://www.dolibarr.org/ns/';
+ $ws_authentication=array(
+ 'dolibarrkey'=>$ws_key,
+ 'sourceapplication'=>'DolibarrWebServiceClient',
+ 'login'=>$ws_user,
+ 'password'=>$ws_password,
+ 'entity'=>$ws_entity
+ );
+
+ //Is sync supplier web services module activated? and everything filled?
+ if (empty($conf->syncsupplierwebservices->enabled)) {
+ setEventMessage($langs->trans("WarningModuleNotActive",$langs->transnoentities("Module2650Name")));
+ } else if (empty($ws_url) || empty($ws_key)) {
+ setEventMessage($langs->trans("ErrorWebServicesFieldsRequired"), 'errors');
+ } else if (empty($ws_user) || empty($ws_password) || empty($ws_thirdparty)) {
+ setEventMessage($langs->trans("ErrorFieldsRequired"), 'errors');
+ }
+ else
+ {
+ //Create SOAP client and connect it to order
+ $soapclient_order = new nusoap_client($ws_url."/webservices/server_order.php");
+ $soapclient_order->soap_defencoding='UTF-8';
+ $soapclient_order->decodeUTF8(false);
+
+ //Create SOAP client and connect it to product/service
+ $soapclient_product = new nusoap_client($ws_url."/webservices/server_productorservice.php");
+ $soapclient_product->soap_defencoding='UTF-8';
+ $soapclient_product->decodeUTF8(false);
+
+ //Prepare the order lines from order
+ $order_lines = array();
+ foreach ($object->lines as $line)
+ {
+ $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $line->ref_supplier);
+ $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, '');
+
+ if ($result_product["result"]["result_code"] == "OK")
+ {
+ $order_lines[] = array(
+ 'desc' => $line->product_desc,
+ 'type' => $line->product_type,
+ 'product_id' => $result_product["product"]["id"],
+ 'vat_rate' => $line->tva_tx,
+ 'qty' => $line->qty,
+ 'price' => $line->price,
+ 'unitprice' => $line->subprice,
+ 'total_net' => $line->total_ht,
+ 'total_vat' => $line->total_tva,
+ 'total' => $line->total_ttc,
+ 'date_start' => $line->date_start,
+ 'date_end' => $line->date_end,
+ );
+ }
+ }
+
+ //Prepare the order header
+ $order = array(
+ 'thirdparty_id' => $ws_thirdparty,
+ 'date' => dol_print_date(dol_now(),'dayrfc'),
+ 'total_net' => $object->total_ht,
+ 'total_var' => $object->total_tva,
+ 'total' => $object->total_ttc,
+ 'lines' => $order_lines
+ );
+
+ $ws_parameters = array('authentication'=>$ws_authentication, 'order' => $order);
+ $result_order = $soapclient_order->call("createOrder", $ws_parameters, $ws_ns, '');
+
+ if (empty($result_order["result"]["result_code"])) //No result, check error str
+ {
+ setEventMessage($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", 'errors');
+ }
+ else if ($result_order["result"]["result_code"] != "OK") //Something went wrong
+ {
+ setEventMessage($langs->trans("SOAPError")." '".$result_order["result"]["result_code"]."' - '".$result_order["result"]["result_label"]."'", 'errors');
+ }
+ else
+ {
+ setEventMessage($langs->trans("RemoteOrderRef")." ".$result_order["ref"], 'mesgs');
+ }
+ }
+ }
+
+ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer)
+ {
+ if ($action == 'addcontact')
+ {
+ if ($object->id > 0)
+ {
+ $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
+ $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
+ }
+
+ if ($result >= 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
}
else
{
- setEventMessage($object->error, 'errors');
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ {
+ $langs->load("errors");
+ setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
+ }
+ else
+ {
+ setEventMessage($object->error, 'errors');
+ }
}
}
- }
- // bascule du statut d'un contact
- else if ($action == 'swapstatut' && $object->id > 0)
- {
- $result=$object->swapContactStatus(GETPOST('ligne'));
- }
-
- // Efface un contact
- else if ($action == 'deletecontact' && $object->id > 0)
- {
- $result = $object->delete_contact($_GET["lineid"]);
-
- if ($result >= 0)
+ // bascule du statut d'un contact
+ else if ($action == 'swapstatut' && $object->id > 0)
{
- header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
- exit;
+ $result=$object->swapContactStatus(GETPOST('ligne'));
}
- else {
- dol_print_error($db);
+
+ // Efface un contact
+ else if ($action == 'deletecontact' && $object->id > 0)
+ {
+ $result = $object->delete_contact($_GET["lineid"]);
+
+ if ($result >= 0)
+ {
+ header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
+ exit;
+ }
+ else {
+ dol_print_error($db);
+ }
}
}
}
@@ -1344,12 +1368,14 @@ elseif (! empty($object->id))
dol_fiche_head($head, 'card', $title, 0, 'order');
+ $formconfirm='';
+
/*
* Confirmation de la suppression de la commande
*/
if ($action == 'delete')
{
- print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
}
@@ -1361,7 +1387,7 @@ elseif (! empty($object->id))
//array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1)
);
// Paiement incomplet. On demande si motif = escompte ou autre
- print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1);
}
@@ -1392,7 +1418,7 @@ elseif (! empty($object->id))
$text.=$notify->confirmMessage('ORDER_SUPPLIER_APPROVE', $object->socid);
}
- print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
}
}
@@ -1425,7 +1451,7 @@ elseif (! empty($object->id))
);
}
- print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
+ $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
}
@@ -1434,7 +1460,7 @@ elseif (! empty($object->id))
*/
if ($action == 'refuse')
{
- print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
+ $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
}
@@ -1443,7 +1469,7 @@ elseif (! empty($object->id))
*/
if ($action == 'cancel')
{
- print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
+ $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
}
@@ -1453,19 +1479,24 @@ elseif (! empty($object->id))
if ($action == 'commande')
{
$date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
- print $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
+ $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
}
- /*
- * Confirmation de la suppression d'une ligne produit
- */
- if ($action == 'delete_product_line')
+ // Confirmation to delete line
+ if ($action == 'ask_deleteline')
{
- print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2);
-
+ $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
}
+ if (!$formconfirm) {
+ $parameters=array('lineid'=>$lineid);
+ $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+ }
+
+ // Print form confirm
+ print $formconfirm;
+
/*
* Commande
*/
@@ -1693,23 +1724,36 @@ elseif (! empty($object->id))
/*
* Lines
*/
+ //$result = $object->getLinesArray();
- print '