| '.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).' | ';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index c3b337c4a16..ebe96b8b485 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -4,10 +4,16 @@
* Copyright (C) 2005-2013 Regis Houssin
* Copyright (C) 2006 Andre Cianfarani
* Copyright (C) 2007-2011 Jean Heimburger
+<<<<<<< HEAD
* Copyright (C) 2010-2013 Juanjo Menent
* Copyright (C) 2013-2014 Cedric GROSS
* Copyright (C) 2013 Marcos García
* Copyright (C) 2011-2014 Alexandre Spangaro
+=======
+ * Copyright (C) 2010-2011 Juanjo Menent
+ * Copyright (C) 2013 Cedric GROSS
+ * Copyright (C) 2013-2014 Marcos García
+>>>>>>> refs/remotes/origin/3.5
*
* 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
@@ -602,7 +608,7 @@ class Product extends CommonObject
foreach ($this->stock_warehouse as $idW => $ObjW)
{
$qty_batch = 0;
- foreach ($ObjW->detail_batch as $detail)
+ foreach ($ObjW->detail_batch as $detail)
{
$qty_batch += $detail->qty;
}
@@ -615,12 +621,12 @@ class Product extends CommonObject
$ObjBatch->qty = $ObjW->real - $qty_batch;
$ObjBatch->fk_product_stock = $ObjW->id;
if ($ObjBatch->create($user,1) < 0)
- {
+ {
$error++;
$this->errors=$ObjBatch->errors;
}
}
- }
+ }
}
// For automatic creation
if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code);
@@ -994,6 +1000,62 @@ class Product extends CommonObject
}
}
+ /*
+ * Sets an accountancy code for a product.
+ * Also calls PRODUCT_MODIFY trigger when modified
+ *
+ * @param string $type It can be 'buy' or 'sell'
+ * @param string $value Accountancy code
+ * @return int <0 KO >0 OK
+ */
+ public function setAccountancyCode($type, $value)
+ {
+ global $user, $langs, $conf;
+
+ $this->db->begin();
+
+ if ($type == 'buy') {
+ $field = 'accountancy_code_buy';
+ } elseif ($type == 'sell') {
+ $field = 'accountancy_code_sell';
+ } else {
+ return -1;
+ }
+
+ $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ";
+ $sql.= "$field = '".$this->db->escape($value)."'";
+ $sql.= " WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::".__FUNCTION__." sql=".$sql, LOG_DEBUG);
+ $resql = $this->db->query($sql);
+
+ if ($resql)
+ {
+ // Call triggers
+ include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ $interface=new Interfaces($this->db);
+ $result=$interface->run_triggers('PRODUCT_MODIFY',$this,$user,$langs,$conf);
+ if ($result < 0)
+ {
+ $this->errors=$interface->errors;
+ $this->db->rollback();
+ return -1;
+ }
+ // End call triggers
+
+ $this->$field = $value;
+
+ $this->db->commit();
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
/**
* Load array this->multilangs
*
@@ -1426,8 +1488,8 @@ class Product extends CommonObject
$this->entity = $obj->entity;
$this->db->free($resql);
-
-
+
+
// Retreive all extrafield for thirdparty
// fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
@@ -1794,7 +1856,7 @@ class Product extends CommonObject
return -1;
}
}
-
+
/**
* Charge tableau des stats contrat pour le produit/service
*
@@ -2977,7 +3039,7 @@ class Product extends CommonObject
function load_virtual_stock()
{
global $conf;
-
+
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT))
{
$stock_commande_client=$stock_commande_fournisseur=0;
@@ -3000,7 +3062,7 @@ class Product extends CommonObject
$result=$this->load_stats_commande_fournisseur(0,'3');
if ($result < 0) dol_print_error($db,$this->error);
$stock_commande_fournisseur=$this->stats_commande_fournisseur['qty'];
-
+
$result=$this->load_stats_reception(0,'3');
if ($result < 0) dol_print_error($db,$this->error);
$stock_reception_fournisseur=$this->stats_reception['qty'];
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index c1fc144e63d..a73d5817b3a 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -6,7 +6,7 @@
* Copyright (C) 2006 Andre Cianfarani
* Copyright (C) 2006 Auguria SARL
* Copyright (C) 2010-2014 Juanjo Menent
- * Copyright (C) 2013 Marcos García
+ * Copyright (C) 2013-2014 Marcos García
* Copyright (C) 2013 Cédric Salvador
* Copyright (C) 2011-2014 Alexandre Spangaro
* Copyright (C) 2014 Cédric Gross
@@ -145,20 +145,18 @@ if (empty($reshook))
}
}
- if ($action == 'setaccountancy_code_buy')
- {
- $result = $object->setValueFrom('accountancy_code_buy', GETPOST('accountancy_code_buy'));
+ if ($action == 'setaccountancy_code_buy') {
+
+ $result = $object->setAccountancyCode('buy', GETPOST('accountancy_code_buy'));
if ($result < 0) setEventMessage(join(',',$object->errors), 'errors');
- else $object->accountancy_code_buy=GETPOST('accountancy_code_buy');
$action="";
}
if ($action == 'setaccountancy_code_sell')
{
- $result = $object->setValueFrom('accountancy_code_sell', GETPOST('accountancy_code_sell'));
- if ($result < 0) setEventMessage(join(',',$object->errors), 'errors');
- else $object->accountancy_code_sell=GETPOST('accountancy_code_sell');
- $action="";
+ $result = $object->setAccountancyCode('sell', GETPOST('accountancy_code_sell'));
+ if ($result < 0) setEventMessage(join(',',$object->errors), 'errors');
+ $action="";
}
// Add a product or service
@@ -221,7 +219,7 @@ if (empty($reshook))
$object->barcode_type_code = $stdobject->barcode_type_code;
$object->barcode_type_coder = $stdobject->barcode_type_coder;
$object->barcode_type_label = $stdobject->barcode_type_label;
-
+
$object->description = dol_htmlcleanlastbr(GETPOST('desc'));
$object->url = GETPOST('url');
$object->note = dol_htmlcleanlastbr(GETPOST('note'));
@@ -335,7 +333,7 @@ if (empty($reshook))
$object->barcode_type_code = $stdobject->barcode_type_code;
$object->barcode_type_coder = $stdobject->barcode_type_coder;
$object->barcode_type_label = $stdobject->barcode_type_label;
-
+
$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->accountancy_code_buy = GETPOST('accountancy_code_buy');
@@ -1329,7 +1327,7 @@ else
if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) $nblignes+=2;
if ($object->isservice()) $nblignes++;
else $nblignes+=4;
-
+
// Photo
if ($showphoto || $showbarcode)
{
@@ -1339,7 +1337,7 @@ else
if ($showbarcode) print $form->showbarcode($object);
print ' | ';
}
-
+
print '
';
// Type
@@ -1351,7 +1349,7 @@ else
print $form->editfieldval("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat);
print '';
}
-
+
if ($showbarcode)
{
// Barcode type
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 0392b073dd4..a6ecf470d38 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -160,14 +160,7 @@ if (empty($reshook))
$object->forme_juridique_code = GETPOST('forme_juridique_code');
$object->effectif_id = GETPOST('effectif_id');
- if (GETPOST("private") == 1)
- {
- $object->typent_id = dol_getIdFromCode($db,'TE_PRIVATE','c_typent');
- }
- else
- {
- $object->typent_id = GETPOST('typent_id');
- }
+ $object->typent_id = GETPOST('typent_id');
$object->client = GETPOST('client');
$object->fournisseur = GETPOST('fournisseur');