Merge pull request #7742 from aspangaro/7.0-accountancyproductvariant

NEW Accountancy Add variant on sell account for intracommunity sales & export sales
This commit is contained in:
Laurent Destailleur 2017-11-06 09:25:14 +01:00 committed by GitHub
commit fa999dfa65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 310 additions and 203 deletions

View File

@ -524,6 +524,9 @@ ALTER TABLE llx_actioncomm_reminder ADD UNIQUE INDEX uk_actioncomm_reminder_uniq
-- May have error due to duplicate keys
ALTER TABLE llx_resource ADD UNIQUE INDEX uk_resource_ref (ref, entity);
ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_intra varchar(32) AFTER accountancy_code_sell;
ALTER TABLE llx_product ADD COLUMN accountancy_code_sell_export varchar(32) AFTER accountancy_code_sell_intra;
-- SPEC : use database type 'double' to store monetary values
ALTER TABLE llx_blockedlog MODIFY COLUMN amounts double(24,8);
ALTER TABLE llx_chargessociales MODIFY COLUMN amount double(24,8);

View File

@ -23,73 +23,75 @@
create table llx_product
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
ref varchar(128) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- Multi company id
rowid integer AUTO_INCREMENT PRIMARY KEY,
ref varchar(128) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- Multi company id
ref_ext varchar(128), -- reference into an external system (not used by dolibarr)
ref_ext varchar(128), -- reference into an external system (not used by dolibarr)
datec datetime,
tms timestamp,
fk_parent integer DEFAULT 0, -- Not used. Used by external modules. Virtual product id
datec datetime,
tms timestamp,
fk_parent integer DEFAULT 0, -- Not used. Used by external modules. Virtual product id
label varchar(255) NOT NULL,
description text,
note_public text,
note text,
customcode varchar(32), -- Optionnal custom code
fk_country integer DEFAULT NULL, -- Optionnal id of original country
price double(24,8) DEFAULT 0,
price_ttc double(24,8) DEFAULT 0,
price_min double(24,8) DEFAULT 0,
price_min_ttc double(24,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT',
cost_price double(24,8) DEFAULT NULL, -- Cost price without tax. Can be used for margin calculation.
default_vat_code varchar(10), -- Same code than into table llx_c_tva (but no constraints). Should be used in priority to find default vat, npr, localtaxes for product.
tva_tx double(6,3), -- Default VAT rate of product
recuperableonly integer NOT NULL DEFAULT '0', -- French NPR VAT
localtax1_tx double(6,3) DEFAULT 0, --
localtax1_type varchar(10) NOT NULL DEFAULT '0', --
localtax2_tx double(6,3) DEFAULT 0, --
localtax2_type varchar(10) NOT NULL DEFAULT '0', --
fk_user_author integer DEFAULT NULL, -- user making creation
fk_user_modif integer, -- user making last change
tosell tinyint DEFAULT 1, -- Product you sell
tobuy tinyint DEFAULT 1, -- Product you buy
onportal tinyint DEFAULT 0, -- If it is a product you sell and you want to sell it on portal (module website must be on)
tobatch tinyint DEFAULT 0 NOT NULL, -- Is it a product that need a batch management (eat-by or lot management)
fk_product_type integer DEFAULT 0, -- Type of product: 0 for regular product, 1 for service, 9 for other (used by external module)
duration varchar(6),
seuil_stock_alerte integer DEFAULT NULL,
url varchar(255),
barcode varchar(255) DEFAULT NULL, -- barcode
fk_barcode_type integer DEFAULT NULL, -- barcode type
accountancy_code_sell varchar(32), -- Selling accountancy code
accountancy_code_buy varchar(32), -- Buying accountancy code
partnumber varchar(32), -- Part/Serial number. TODO To use it into screen if not a duplicate of barcode.
weight float DEFAULT NULL,
weight_units tinyint DEFAULT NULL,
length float DEFAULT NULL,
length_units tinyint DEFAULT NULL,
width float DEFAULT NULL,
width_units tinyint DEFAULT NULL,
height float DEFAULT NULL,
height_units tinyint DEFAULT NULL,
surface float DEFAULT NULL,
surface_units tinyint DEFAULT NULL,
volume float DEFAULT NULL,
volume_units tinyint DEFAULT NULL,
stock real, -- Current physical stock (dernormalized field)
pmp double(24,8) DEFAULT 0 NOT NULL, -- To store valuation of stock calculated using average price method, for this product
fifo double(24,8), -- To store valuation of stock calculated using fifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table.
lifo double(24,8), -- To store valuation of stock calculated using lifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table.
canvas varchar(32) DEFAULT NULL,
finished tinyint DEFAULT NULL, -- 1=manufactured product, 0=matiere premiere
hidden tinyint DEFAULT 0, -- Not used. Deprecated.
import_key varchar(14), -- Import key
model_pdf varchar(255), -- model save dodument used
fk_price_expression integer, -- Link to the rule for dynamic price calculation
desiredstock integer DEFAULT 0,
fk_unit integer DEFAULT NULL,
price_autogen TINYINT DEFAULT 0
label varchar(255) NOT NULL,
description text,
note_public text,
note text,
customcode varchar(32), -- Optionnal custom code
fk_country integer DEFAULT NULL, -- Optionnal id of original country
price double(24,8) DEFAULT 0,
price_ttc double(24,8) DEFAULT 0,
price_min double(24,8) DEFAULT 0,
price_min_ttc double(24,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT',
cost_price double(24,8) DEFAULT NULL, -- Cost price without tax. Can be used for margin calculation.
default_vat_code varchar(10), -- Same code than into table llx_c_tva (but no constraints). Should be used in priority to find default vat, npr, localtaxes for product.
tva_tx double(6,3), -- Default VAT rate of product
recuperableonly integer NOT NULL DEFAULT '0', -- French NPR VAT
localtax1_tx double(6,3) DEFAULT 0,
localtax1_type varchar(10) NOT NULL DEFAULT '0',
localtax2_tx double(6,3) DEFAULT 0,
localtax2_type varchar(10) NOT NULL DEFAULT '0',
fk_user_author integer DEFAULT NULL, -- user making creation
fk_user_modif integer, -- user making last change
tosell tinyint DEFAULT 1, -- Product you sell
tobuy tinyint DEFAULT 1, -- Product you buy
onportal tinyint DEFAULT 0, -- If it is a product you sell and you want to sell it on portal (module website must be on)
tobatch tinyint DEFAULT 0 NOT NULL, -- Is it a product that need a batch management (eat-by or lot management)
fk_product_type integer DEFAULT 0, -- Type of product: 0 for regular product, 1 for service, 9 for other (used by external module)
duration varchar(6),
seuil_stock_alerte integer DEFAULT NULL,
url varchar(255),
barcode varchar(255) DEFAULT NULL, -- barcode
fk_barcode_type integer DEFAULT NULL, -- barcode type
accountancy_code_sell varchar(32), -- Selling accountancy code
accountancy_code_sell_intra varchar(32), -- Selling accountancy code for vat intracommunity
accountancy_code_sell_export varchar(32), -- Selling accountancy code for vat export
accountancy_code_buy varchar(32), -- Buying accountancy code
partnumber varchar(32), -- Part/Serial number. TODO To use it into screen if not a duplicate of barcode.
weight float DEFAULT NULL,
weight_units tinyint DEFAULT NULL,
length float DEFAULT NULL,
length_units tinyint DEFAULT NULL,
width float DEFAULT NULL,
width_units tinyint DEFAULT NULL,
height float DEFAULT NULL,
height_units tinyint DEFAULT NULL,
surface float DEFAULT NULL,
surface_units tinyint DEFAULT NULL,
volume float DEFAULT NULL,
volume_units tinyint DEFAULT NULL,
stock real, -- Current physical stock (dernormalized field)
pmp double(24,8) DEFAULT 0 NOT NULL, -- To store valuation of stock calculated using average price method, for this product
fifo double(24,8), -- To store valuation of stock calculated using fifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table.
lifo double(24,8), -- To store valuation of stock calculated using lifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table.
canvas varchar(32) DEFAULT NULL,
finished tinyint DEFAULT NULL, -- 1=manufactured product, 0=matiere premiere
hidden tinyint DEFAULT 0, -- Not used. Deprecated.
import_key varchar(14), -- Import key
model_pdf varchar(255), -- model save dodument used
fk_price_expression integer, -- Link to the rule for dynamic price calculation
desiredstock integer DEFAULT 0,
fk_unit integer DEFAULT NULL,
price_autogen tinyint DEFAULT 0
)ENGINE=innodb;

View File

@ -22,6 +22,8 @@ MassBarcodeInit=Mass barcode init
MassBarcodeInitDesc=This page can be used to initialize a barcode on objects that does not have barcode defined. Check before that setup of module barcode is complete.
ProductAccountancyBuyCode=Accounting code (purchase)
ProductAccountancySellCode=Accounting code (sale)
ProductAccountancySellIntraCode=Accounting code (sale intra-community)
ProductAccountancySellExportCode=Accounting code (sale export)
ProductOrService=Product or Service
ProductsAndServices=Products and Services
ProductsOrServices=Products or Services

View File

@ -8,7 +8,7 @@
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2014-2015 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
@ -306,9 +306,13 @@ if (empty($reshook))
$object->fk_unit = GETPOST('units');
$accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra');
$accountancy_code_sell_export = GETPOST('accountancy_code_sell_export');
$accountancy_code_buy = GETPOST('accountancy_code_buy');
if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
if ($accountancy_code_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; }
if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; }
if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
// MultiPrix
@ -430,9 +434,13 @@ if (empty($reshook))
$object->barcode_type_label = $stdobject->barcode_type_label;
$accountancy_code_sell = GETPOST('accountancy_code_sell');
$accountancy_code_sell_intra = GETPOST('accountancy_code_sell_intra');
$accountancy_code_sell_export = GETPOST('accountancy_code_sell_export');
$accountancy_code_buy = GETPOST('accountancy_code_buy');
if ($accountancy_code_sell <= 0) { $object->accountancy_code_sell = ''; } else { $object->accountancy_code_sell = $accountancy_code_sell; }
if ($accountancy_code_sell_intra <= 0) { $object->accountancy_code_sell_intra = ''; } else { $object->accountancy_code_sell_intra = $accountancy_code_sell_intra; }
if ($accountancy_code_sell_export <= 0) { $object->accountancy_code_sell_export = ''; } else { $object->accountancy_code_sell_export = $accountancy_code_sell_export; }
if ($accountancy_code_buy <= 0) { $object->accountancy_code_buy = ''; } else { $object->accountancy_code_buy = $accountancy_code_buy; }
// Fill array 'array_options' with data from add form
@ -1154,42 +1162,64 @@ else
if (! empty($conf->accounting->enabled))
{
// Accountancy_code_sell
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, '');
print '</td></tr>';
// Accountancy_code_sell
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_code_sell'), 'accountancy_code_sell', 1, null, 1, 1, '');
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
// Accountancy_code_sell_intra
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_code_sell_intra'), 'accountancy_code_sell_intra', 1, null, 1, 1, '');
print '</td></tr>';
// Accountancy_code_sell_export
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_code_sell_export'), 'accountancy_code_sell_export', 1, null, 1, 1, '');
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
print $formaccounting->select_account(GETPOST('accountancy_code_buy'), 'accountancy_code_buy', 1, null, 1, 1, '');
print '</td></tr>';
print '</td></tr>';
}
else // For external software
{
// Accountancy_code_sell
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';
// Accountancy_code_sell
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
}
// Accountancy_code_sell_intra
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell_intra" value="'.$object->accountancy_code_sell_intra.'">';
print '</td></tr>';
// Accountancy_code_sell_export
print '<tr><td class="titlefieldcreate">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_sell_export" value="'.$object->accountancy_code_sell_export.'">';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td class="maxwidthonsmartphone"><input class="minwidth100" name="accountancy_code_buy" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
}
print '</table>';
dol_fiche_end();
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="' . $langs->trans("Create") . '">';
print ' &nbsp; &nbsp; ';
print ' &nbsp; &nbsp; ';
print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
print '</div>';
print '</form>';
}
print '</form>';
}
/*
* Product card
@ -1448,42 +1478,64 @@ else
if (! empty($conf->accounting->enabled))
{
// Accountancy_code_sell
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
// Accountancy_code_sell
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td>';
print $formaccounting->select_account($object->accountancy_code_sell, 'accountancy_code_sell', 1, '', 1, 1);
print '</td></tr>';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
// Accountancy_code_sell_intra
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
print '<td>';
print $formaccounting->select_account($object->accountancy_code_sell_intra, 'accountancy_code_sell_intra', 1, '', 1, 1);
print '</td></tr>';
// Accountancy_code_sell_export
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
print '<td>';
print $formaccounting->select_account($object->accountancy_code_sell_export, 'accountancy_code_sell_export', 1, '', 1, 1);
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td>';
print $formaccounting->select_account($object->accountancy_code_buy, 'accountancy_code_buy', 1, '', 1, 1);
print '</td></tr>';
print '</td></tr>';
}
else // For external software
{
// Accountancy_code_sell
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';
// Accountancy_code_sell
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellCode").'</td>';
print '<td><input name="accountancy_code_sell" class="maxwidth200" value="'.$object->accountancy_code_sell.'">';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
}
// Accountancy_code_sell_intra
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellIntraCode").'</td>';
print '<td><input name="accountancy_code_sell_intra" class="maxwidth200" value="'.$object->accountancy_code_sell_intra.'">';
print '</td></tr>';
// Accountancy_code_sell_export
print '<tr><td class="titlefield">'.$langs->trans("ProductAccountancySellExportCode").'</td>';
print '<td><input name="accountancy_code_sell_export" class="maxwidth200" value="'.$object->accountancy_code_sell_export.'">';
print '</td></tr>';
// Accountancy_code_buy
print '<tr><td>'.$langs->trans("ProductAccountancyBuyCode").'</td>';
print '<td><input name="accountancy_code_buy" class="maxwidth200" value="'.$object->accountancy_code_buy.'">';
print '</td></tr>';
}
print '</table>';
dol_fiche_end();
dol_fiche_end();
print '<div class="center">';
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>';
}
print '</form>';
}
// Fiche en mode visu
else
{
@ -1575,35 +1627,65 @@ else
print '</td></tr>'."\n";
}
// Accountancy sell code
// Accountancy sell code
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancySellCode");
print '</td><td colspan="2">';
print $langs->trans("ProductAccountancySellCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled))
{
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch('',$object->accountancy_code_sell,1);
print $accountingaccount->getNomUrl(0,1,1,'',1);
} else {
} else {
print $object->accountancy_code_sell;
}
print '</td></tr>';
// Accountancy buy code
// Accountancy sell code intra-community
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancyBuyCode");
print '</td><td colspan="2">';
print $langs->trans("ProductAccountancySellIntraCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled))
{
$accountingaccount2 = new AccountingAccount($db);
$accountingaccount2->fetch('',$object->accountancy_code_buy,1);
$accountingaccount2->fetch('',$object->accountancy_code_sell_intra,1);
print $accountingaccount2->getNomUrl(0,1,1,'',1);
} else {
} else {
print $object->accountancy_code_sell_intra;
}
print '</td></tr>';
// Accountancy sell code export
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancySellExportCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled))
{
$accountingaccount3 = new AccountingAccount($db);
$accountingaccount3->fetch('',$object->accountancy_code_sell_export,1);
print $accountingaccount3->getNomUrl(0,1,1,'',1);
} else {
print $object->accountancy_code_sell_export;
}
print '</td></tr>';
// Accountancy buy code
print '<tr><td class="nowrap">';
print $langs->trans("ProductAccountancyBuyCode");
print '</td><td colspan="2">';
if (! empty($conf->accounting->enabled))
{
$accountingaccount4 = new AccountingAccount($db);
$accountingaccount4->fetch('',$object->accountancy_code_buy,1);
print $accountingaccount4->getNomUrl(0,1,1,'',1);
} else {
print $object->accountancy_code_buy;
}
print '</td></tr>';
print '</td></tr>';
// Status (to sell)
/*

View File

@ -8,7 +8,7 @@
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2013-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2011-2014 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2014 Henry Florian <florian.henry@open-concept.pro>
* Copyright (C) 2014-2016 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Ion agorria <ion@agorria.com>
@ -228,6 +228,8 @@ class Product extends CommonObject
public $volume_units;
public $accountancy_code_buy;
public $accountancy_code_buy_intra;
public $accountancy_code_buy_export;
public $accountancy_code_sell;
/**
@ -436,13 +438,15 @@ class Product extends CommonObject
$price_min_ttc = price2num($this->price_min * (1 + ($this->tva_tx / 100)),'MU');
}
$this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_sell= trim($this->accountancy_code_sell);
$this->accountancy_code_sell_intra= trim($this->accountancy_code_sell_intra);
$this->accountancy_code_sell_export= trim($this->accountancy_code_sell_export);
// Barcode value
$this->barcode=trim($this->barcode);
// Check parameters
// Check parameters
if (empty($this->label))
{
$this->error='ErrorMandatoryParametersNotProvided';
@ -477,19 +481,19 @@ class Product extends CommonObject
dol_syslog(get_class($this)."::create ref=".$this->ref." price=".$this->price." price_ttc=".$this->price_ttc." tva_tx=".$this->tva_tx." price_base_type=".$this->price_base_type, LOG_DEBUG);
$now=dol_now();
$now=dol_now();
$this->db->begin();
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code);
// Check more parameters
// If error, this->errors[] is filled
$result = $this->verify();
// If error, this->errors[] is filled
$result = $this->verify();
if ($result >= 0)
{
if ($result >= 0)
{
$sql = "SELECT count(*) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE entity IN (".getEntity('product').")";
@ -519,6 +523,8 @@ class Product extends CommonObject
$sql.= ", tosell";
$sql.= ", accountancy_code_buy";
$sql.= ", accountancy_code_sell";
$sql.= ", accountancy_code_sell_intra";
$sql.= ", accountancy_code_sell_export";
$sql.= ", canvas";
$sql.= ", finished";
$sql.= ", tobatch";
@ -540,6 +546,8 @@ class Product extends CommonObject
$sql.= ", ".$this->status_buy;
$sql.= ", '".$this->db->escape($this->accountancy_code_buy)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_sell)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_sell_intra)."'";
$sql.= ", '".$this->db->escape($this->accountancy_code_sell_export)."'";
$sql.= ", '".$this->db->escape($this->canvas)."'";
$sql.= ", ".((! isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished);
$sql.= ", ".((empty($this->status_batch) || $this->status_batch < 0)? '0':$this->status_batch);
@ -565,25 +573,25 @@ class Product extends CommonObject
{
if ($this->update($id, $user, true, 'add') <= 0)
{
$error++;
$error++;
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
$this->error=$this->db->lasterror();
}
}
else
{
$error++;
$this->error='ErrorFailedToGetInsertedId';
$this->error='ErrorFailedToGetInsertedId';
}
}
else
{
$error++;
$this->error=$this->db->lasterror();
$this->error=$this->db->lasterror();
}
}
else
@ -597,15 +605,15 @@ class Product extends CommonObject
else
{
$error++;
$this->error=$this->db->lasterror();
$this->error=$this->db->lasterror();
}
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('PRODUCT_CREATE',$user);
if ($result < 0) { $error++; }
// End call triggers
// Call trigger
$result=$this->call_trigger('PRODUCT_CREATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error)
@ -772,6 +780,8 @@ class Product extends CommonObject
$this->accountancy_code_buy = trim($this->accountancy_code_buy);
$this->accountancy_code_sell= trim($this->accountancy_code_sell);
$this->accountancy_code_sell_intra= trim($this->accountancy_code_sell_intra);
$this->accountancy_code_sell_export= trim($this->accountancy_code_sell_export);
$this->db->begin();
@ -883,6 +893,8 @@ class Product extends CommonObject
$sql.= ", duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) ."'";
$sql.= ", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy)."'";
$sql.= ", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell)."'";
$sql.= ", accountancy_code_sell_intra= '" . $this->db->escape($this->accountancy_code_sell_intra)."'";
$sql.= ", accountancy_code_sell_export= '" . $this->db->escape($this->accountancy_code_sell_export)."'";
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
$sql.= ", cost_price = " . ($this->cost_price != '' ? $this->db->escape($this->cost_price) : 'null');
$sql.= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit);
@ -1325,7 +1337,7 @@ 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 $type It can be 'buy', 'sell', 'sell_intra' or 'sell_export'
* @param string $value Accountancy code
* @return int <0 KO >0 OK
*/
@ -1339,6 +1351,10 @@ class Product extends CommonObject
$field = 'accountancy_code_buy';
} elseif ($type == 'sell') {
$field = 'accountancy_code_sell';
} elseif ($type == 'sell_intra') {
$field = 'accountancy_code_sell_intra';
} elseif ($type == 'sell_export') {
$field = 'accountancy_code_sell_export';
} else {
return -1;
}
@ -1831,7 +1847,7 @@ class Product extends CommonObject
$sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas, weight, weight_units,";
$sql.= " length, length_units, width, width_units, height, height_units,";
$sql.= " surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
$sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,";
$sql.= " accountancy_code_buy, accountancy_code_sell, accountancy_code_sell_intra, accountancy_code_sell_export, stock, pmp,";
$sql.= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit,";
$sql.= " fk_price_expression, price_autogen";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
@ -1850,78 +1866,80 @@ class Product extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_ext = $obj->ref_ext;
$this->label = $obj->label;
$this->description = $obj->description;
$this->url = $obj->url;
$this->note_private = $obj->note_private;
$this->note = $obj->note_private; // deprecated
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_ext = $obj->ref_ext;
$this->label = $obj->label;
$this->description = $obj->description;
$this->url = $obj->url;
$this->note_private = $obj->note_private;
$this->note = $obj->note_private; // deprecated
$this->type = $obj->fk_product_type;
$this->status = $obj->tosell;
$this->status_buy = $obj->tobuy;
$this->status_batch = $obj->tobatch;
$this->type = $obj->fk_product_type;
$this->status = $obj->tosell;
$this->status_buy = $obj->tobuy;
$this->status_batch = $obj->tobatch;
$this->customcode = $obj->customcode;
$this->country_id = $obj->fk_country;
$this->country_code = getCountry($this->country_id,2,$this->db);
$this->price = $obj->price;
$this->price_ttc = $obj->price_ttc;
$this->price_min = $obj->price_min;
$this->price_min_ttc = $obj->price_min_ttc;
$this->price_base_type = $obj->price_base_type;
$this->cost_price = $obj->cost_price;
$this->default_vat_code = $obj->default_vat_code;
$this->tva_tx = $obj->tva_tx;
$this->customcode = $obj->customcode;
$this->country_id = $obj->fk_country;
$this->country_code = getCountry($this->country_id,2,$this->db);
$this->price = $obj->price;
$this->price_ttc = $obj->price_ttc;
$this->price_min = $obj->price_min;
$this->price_min_ttc = $obj->price_min_ttc;
$this->price_base_type = $obj->price_base_type;
$this->cost_price = $obj->cost_price;
$this->default_vat_code = $obj->default_vat_code;
$this->tva_tx = $obj->tva_tx;
//! French VAT NPR
$this->tva_npr = $obj->tva_npr;
$this->recuperableonly = $obj->tva_npr; // For backward compatibility
$this->tva_npr = $obj->tva_npr;
$this->recuperableonly = $obj->tva_npr; // For backward compatibility
//! Local taxes
$this->localtax1_tx = $obj->localtax1_tx;
$this->localtax2_tx = $obj->localtax2_tx;
$this->localtax1_type = $obj->localtax1_type;
$this->localtax2_type = $obj->localtax2_type;
$this->localtax1_tx = $obj->localtax1_tx;
$this->localtax2_tx = $obj->localtax2_tx;
$this->localtax1_type = $obj->localtax1_type;
$this->localtax2_type = $obj->localtax2_type;
$this->finished = $obj->finished;
$this->duration = $obj->duration;
$this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1);
$this->duration_unit = substr($obj->duration,-1);
$this->canvas = $obj->canvas;
$this->weight = $obj->weight;
$this->weight_units = $obj->weight_units;
$this->length = $obj->length;
$this->length_units = $obj->length_units;
$this->width = $obj->width;
$this->width_units = $obj->width_units;
$this->height = $obj->height;
$this->height_units = $obj->height_units;
$this->finished = $obj->finished;
$this->duration = $obj->duration;
$this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1);
$this->duration_unit = substr($obj->duration,-1);
$this->canvas = $obj->canvas;
$this->weight = $obj->weight;
$this->weight_units = $obj->weight_units;
$this->length = $obj->length;
$this->length_units = $obj->length_units;
$this->width = $obj->width;
$this->width_units = $obj->width_units;
$this->height = $obj->height;
$this->height_units = $obj->height_units;
$this->surface = $obj->surface;
$this->surface_units = $obj->surface_units;
$this->volume = $obj->volume;
$this->volume_units = $obj->volume_units;
$this->barcode = $obj->barcode;
$this->barcode_type = $obj->fk_barcode_type;
$this->surface = $obj->surface;
$this->surface_units = $obj->surface_units;
$this->volume = $obj->volume;
$this->volume_units = $obj->volume_units;
$this->barcode = $obj->barcode;
$this->barcode_type = $obj->fk_barcode_type;
$this->accountancy_code_buy = $obj->accountancy_code_buy;
$this->accountancy_code_sell = $obj->accountancy_code_sell;
$this->accountancy_code_buy = $obj->accountancy_code_buy;
$this->accountancy_code_sell = $obj->accountancy_code_sell;
$this->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra;
$this->accountancy_code_sell_export = $obj->accountancy_code_sell_export;
$this->seuil_stock_alerte = $obj->seuil_stock_alerte;
$this->desiredstock = $obj->desiredstock;
$this->stock_reel = $obj->stock;
$this->pmp = $obj->pmp;
$this->seuil_stock_alerte = $obj->seuil_stock_alerte;
$this->desiredstock = $obj->desiredstock;
$this->stock_reel = $obj->stock;
$this->pmp = $obj->pmp;
$this->date_creation = $obj->datec;
$this->date_modification = $obj->tms;
$this->import_key = $obj->import_key;
$this->entity = $obj->entity;
$this->date_creation = $obj->datec;
$this->date_modification = $obj->tms;
$this->import_key = $obj->import_key;
$this->entity = $obj->entity;
$this->ref_ext = $obj->ref_ext;
$this->fk_price_expression = $obj->fk_price_expression;
$this->fk_unit = $obj->fk_unit;
$this->price_autogen = $obj->price_autogen;
$this->ref_ext = $obj->ref_ext;
$this->fk_price_expression = $obj->fk_price_expression;
$this->fk_unit = $obj->fk_unit;
$this->price_autogen = $obj->price_autogen;
$this->db->free($resql);