Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2019-12-09 09:17:12 +01:00
commit 7797c5628f
11 changed files with 339 additions and 41 deletions

View File

@ -44,6 +44,7 @@ if ($cancel)
$action = '';
}
// Action to add record
if ($action == 'add' && !empty($permissiontoadd))
{

View File

@ -621,7 +621,7 @@ abstract class CommonObject
$thirdpartyid = $object->fk_soc;
}
$out = '<!-- BEGIN part to show address block -->';
$out = '';
$outdone = 0;
$coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT);
@ -682,7 +682,7 @@ abstract class CommonObject
$out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', '&nbsp;', 'fax', $langs->trans("Fax")); $outdone++;
}
$out .= '<div style="clear: both;"></div>';
if ($out) $out .= '<div style="clear: both;"></div>';
$outdone = 0;
if (!empty($this->email))
{
@ -695,32 +695,36 @@ abstract class CommonObject
$out .= dol_print_url($this->url, '_blank', 0, 1);
$outdone++;
}
$out .= '<div style="clear: both;">';
if (!empty($conf->socialnetworks->enabled))
{
$outsocialnetwork = '';
if (is_array($this->socialnetworks) && count($this->socialnetworks) > 0) {
foreach ($this->socialnetworks as $key => $value) {
$out .= dol_print_socialnetworks($value, $this->id, $object->id, $key);
$outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key);
$outdone++;
}
} else {
if ($this->skype) $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
if ($this->skype) $outsocialnetwork .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype');
$outdone++;
if ($this->jabberid) $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
if ($this->jabberid) $outsocialnetwork .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber');
$outdone++;
if ($this->twitter) $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
if ($this->twitter) $outsocialnetwork .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter');
$outdone++;
if ($this->facebook) $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
if ($this->facebook) $outsocialnetwork .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook');
$outdone++;
if ($this->linkedin) $out .= dol_print_socialnetworks($this->linkedin, $this->id, $object->id, 'linkedin');
if ($this->linkedin) $outsocialnetwork .= dol_print_socialnetworks($this->linkedin, $this->id, $object->id, 'linkedin');
$outdone++;
}
if ($outsocialnetwork) {
$out .= '<div style="clear: both;">'.$outsocialnetwork.'</div>';
}
}
$out .= '</div>';
$out .= '<!-- END Part to show address block -->';
return $out;
if ($out) return '<!-- BEGIN part to show address block -->'."\n".$out.'<!-- END Part to show address block -->'."\n";
else return '';
}
/**
@ -4118,7 +4122,7 @@ abstract class CommonObject
$i = 0;
print "<tbody>\n";
print "<!-- begin printObjectLines() --><tbody>\n";
foreach ($this->lines as $line)
{
//Line extrafield
@ -7317,7 +7321,7 @@ abstract class CommonObject
global $conf;
$queryarray = array();
foreach ($this->fields as $field=>$info) // Loop on definition of fields
foreach ($this->fields as $field => $info) // Loop on definition of fields
{
// Depending on field type ('datetime', ...)
if ($this->isDate($info))
@ -7553,6 +7557,8 @@ abstract class CommonObject
{
$error++;
$this->errors[] = $this->db->lasterror();
} else {
$this->ref = '(PROV'.$this->id.')';
}
}
}

View File

@ -521,6 +521,8 @@ CREATE TABLE llx_mrp_production(
fk_product integer NOT NULL,
fk_warehouse integer,
qty integer NOT NULL DEFAULT 1,
qty_frozen smallint DEFAULT 0,
disable_stock_change smallint DEFAULT 0,
batch varchar(30),
role varchar(10), -- 'toconsume' or 'toproduce' (initialized at MO creation), 'consumed' or 'produced' (added after MO validation)
fk_mrp_production integer, -- if role = 'consumed', id of line with role 'toconsume', if role = 'produced' id of line with role 'toproduce'
@ -532,6 +534,8 @@ CREATE TABLE llx_mrp_production(
import_key varchar(14)
) ENGINE=innodb;
ALTER TABLE llx_mrp_production ADD COLUMN qty_frozen smallint DEFAULT 0;
ALTER TABLE llx_mrp_production ADD COLUMN disable_stock_change smallint DEFAULT 0;
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_mo FOREIGN KEY (fk_mo) REFERENCES llx_mrp_mo (rowid);
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
ALTER TABLE llx_mrp_production ADD CONSTRAINT fk_mrp_production_stock_movement FOREIGN KEY (fk_stock_movement) REFERENCES llx_stock_mouvement (rowid);

View File

@ -21,6 +21,8 @@ CREATE TABLE llx_mrp_production(
fk_product integer NOT NULL,
fk_warehouse integer,
qty integer NOT NULL DEFAULT 1,
qty_frozen smallint DEFAULT 0,
disable_stock_change smallint DEFAULT 0,
batch varchar(30),
role varchar(10), -- 'toconsume' or 'toproduce' (initialized at MO creation), 'consumed' or 'produced' (added after MO validation)
fk_mrp_production integer, -- if role = 'consumed', id of line with role 'toconsume', if role = 'produced' id of line with role 'toproduce'

View File

@ -53,3 +53,4 @@ CreateMO=Create MO
ToConsume=A consommer
Manufactured=Fabriqué
TheProductXIsAlreadyTheProductToProduce=The product to add is already the product to produce.
ForAQuantityOf1=For a quantity to produce of 1

View File

@ -157,32 +157,32 @@ class Mo extends CommonObject
/**
* @var int Name of subtable line
*/
//public $table_element_line = 'mrp_moline';
public $table_element_line = 'mo_production';
/**
* @var int Field with ID of parent key if this field has a parent
*/
//public $fk_element = 'fk_mo';
public $fk_element = 'fk_mo';
/**
* @var int Name of subtable class that manage subtable lines
*/
//public $class_element_line = 'Moline';
public $class_element_line = 'MoLine';
/**
* @var array List of child tables. To test if we can delete object.
*/
//protected $childtables=array();
protected $childtables=array();
/**
* @var array List of child tables. To know object to delete on cascade.
*/
//protected $childtablesoncascade=array('mrp_modet');
protected $childtablesoncascade=array('mrp_production');
/**
* @var MoLine[] Array of subtable lines
*/
//public $lines = array();
public $lines = array();
@ -231,13 +231,57 @@ class Mo extends CommonObject
*/
public function create(User $user, $notrigger = false)
{
global $conf;
$error = 0;
$this->db->begin();
$result = $this->createCommon($user, $notrigger);
if ($result <= 0) {
$error++;
}
// Insert lines in mrp_production table
if (! $error && $this->fk_bom > 0)
{
include_once DOL_DOCULENT_ROOT.'/bom/class/bom.class.php';
$bom = new Bom($this->db);
$bom->fetch($this->fk_bom);
if ($bom->id > 0)
{
foreach($bom->lines as $line)
{
$moline = new MoLine($this->db);
if ($result > 0) {
$moline->fk_mo = $this->id;
$moline->qty = $line->qty * $this->qty * $bom->efficiency;
if ($moline->qty <= 0) {
$error++;
$this->error = "BadValueForquantityToConsume";
break;
}
else {
$moline->fk_product = $line->fk_product;
$moline->role = 'toconsume';
$moline->position = $line->position;
$moline->qty_frozen = $line->qty_frozen;
$moline->disable_stock_change = $line->disable_stock_change;
$resultline = $moline->create($user);
if ($resultline <= 0) {
$error++;
$this->error = $moline->error;
$this->errors = $moline->errors;
dol_print_error($this->db, $moline->error, $moline->errors);
break;
}
}
}
}
}
if (! $error) {
$this->db->commit();
} else {
$this->db->rollback();
@ -838,8 +882,232 @@ class Mo extends CommonObject
/**
* Class MoLine. You can also remove this and generate a CRUD class for lines objects.
*/
class MoLine
class MoLine extends CommonObjectLine
{
// To complete with content of an object MoLine
// We should have a field rowid, fk_mo and position
/**
* @var string ID to identify managed object
*/
public $element = 'mrp_production';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'mrp_production';
/**
* @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
*/
public $ismultientitymanaged = 0;
/**
* @var int Does moline support extrafields ? 0=No, 1=Yes
*/
public $isextrafieldmanaged = 0;
public $fields=array(
'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
'fk_mo' =>array('type'=>'integer', 'label'=>'Fk mo', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15),
'position' =>array('type'=>'integer', 'label'=>'Position', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>20),
'fk_product' =>array('type'=>'integer', 'label'=>'Fk product', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25),
'fk_warehouse' =>array('type'=>'integer', 'label'=>'Fk warehouse', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
'qty' =>array('type'=>'integer', 'label'=>'Qty', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35),
'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'),
'disable_stock_change' => array('type'=>'smallint', 'label'=>'DisableStockChange', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'position'=>108, 'css'=>'maxwidth50imp', 'help'=>'DisableStockChangeHelp'),
'batch' =>array('type'=>'varchar(30)', 'label'=>'Batch', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
'role' =>array('type'=>'varchar(10)', 'label'=>'Role', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
'fk_mrp_production' =>array('type'=>'integer', 'label'=>'Fk mrp production', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
'fk_stock_movement' =>array('type'=>'integer', 'label'=>'Fk stock movement', 'enabled'=>1, 'visible'=>-1, 'position'=>155),
'date_creation' =>array('type'=>'datetime', 'label'=>'Date creation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>160),
'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>165),
'fk_user_creat' =>array('type'=>'integer', 'label'=>'Fk user creat', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>170),
'fk_user_modif' =>array('type'=>'integer', 'label'=>'Fk user modif', 'enabled'=>1, 'visible'=>-1, 'position'=>175),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportKey', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
);
public $rowid;
public $fk_mo;
public $position;
public $fk_product;
public $fk_warehouse;
public $qty;
public $qty_frozen;
public $disable_stock_change;
public $batch;
public $role;
public $fk_mrp_production;
public $fk_stock_movement;
public $date_creation;
public $tms;
public $fk_user_creat;
public $fk_user_modif;
public $import_key;
/**
* Constructor
*
* @param DoliDb $db Database handler
*/
public function __construct(DoliDB $db)
{
global $conf, $langs;
$this->db = $db;
if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
// Unset fields that are disabled
foreach ($this->fields as $key => $val)
{
if (isset($val['enabled']) && empty($val['enabled']))
{
unset($this->fields[$key]);
}
}
// Translate some data of arrayofkeyval
if (is_object($langs))
{
foreach($this->fields as $key => $val)
{
if (is_array($val['arrayofkeyval']))
{
foreach($val['arrayofkeyval'] as $key2 => $val2)
{
$this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
}
}
}
}
}
/**
* Create object into database
*
* @param User $user User that creates
* @param bool $notrigger false=launch triggers after, true=disable triggers
* @return int <0 if KO, Id of created object if OK
*/
public function create(User $user, $notrigger = false)
{
return $this->createCommon($user, $notrigger);
}
/**
* Load object in memory from the database
*
* @param int $id Id object
* @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK
*/
public function fetch($id, $ref = null)
{
$result = $this->fetchCommon($id, $ref);
if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
return $result;
}
/**
* Load list of objects in memory from the database.
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit limit
* @param int $offset Offset
* @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
* @param string $filtermode Filter mode (AND or OR)
* @return array|int int <0 if KO, array of pages if OK
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
{
global $conf;
dol_syslog(__METHOD__, LOG_DEBUG);
$records = array();
$sql = 'SELECT ';
$sql .= $this->getFieldList();
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
else $sql .= ' WHERE 1 = 1';
// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key.'='.$value;
}
elseif (strpos($key, 'date') !== false) {
$sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
}
elseif ($key == 'customsql') {
$sqlwhere[] = $value;
}
else {
$sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
}
if (!empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
if (!empty($limit)) {
$sql .= ' '.$this->db->plimit($limit, $offset);
}
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < min($limit, $num))
{
$obj = $this->db->fetch_object($resql);
$record = new self($this->db);
$record->setVarsFromFetchObj($obj);
$records[$record->id] = $record;
$i++;
}
$this->db->free($resql);
return $records;
} else {
$this->errors[] = 'Error '.$this->db->lasterror();
dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
return -1;
}
}
/**
* Update object into database
*
* @param User $user User that modifies
* @param bool $notrigger false=launch triggers after, true=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function update(User $user, $notrigger = false)
{
return $this->updateCommon($user, $notrigger);
}
/**
* Delete object in database
*
* @param User $user User that deletes
* @param bool $notrigger false=launch triggers after, true=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function delete(User $user, $notrigger = false)
{
return $this->deleteCommon($user, $notrigger);
//return $this->deleteCommon($user, $notrigger, 1);
}
}

View File

@ -136,8 +136,9 @@ if ($object->id > 0)
// ------------------------------------------------------------
$linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
$morehtmlref = '<div class="refidno">';
$morehtmlref = '';
/*
$morehtmlref = '<div class="refidno">';
// Ref customer
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
@ -175,9 +176,9 @@ if ($object->id > 0)
$morehtmlref.='';
}
}
}*/
}
$morehtmlref .= '</div>';
*/
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

View File

@ -93,10 +93,13 @@ if (GETPOST('fk_bom', 'int'))
{
$objectbom->fetch(GETPOST('fk_bom', 'int'));
$_POST['fk_product'] = $objectbom->fk_product;
$_POST['qty'] = $objectbom->qty;
$_POST['fk_warehouse'] = $objectbom->fk_warehouse;
$_POST['note_private'] = $objectbom->note_private;
if ($action != 'add') {
// We force calling parameters if we are not in the submit of creation of MO
$_POST['fk_product'] = $objectbom->fk_product;
$_POST['qty'] = $objectbom->qty;
$_POST['fk_warehouse'] = $objectbom->fk_warehouse;
$_POST['note_private'] = $objectbom->note_private;
}
}
// Security check - Protection if external user
@ -279,7 +282,7 @@ if ($action == 'create')
print '</div>';
if (GETPOST('fk_bom', 'int') > 0) {
print load_fiche_titre($langs->trans("ToConsume"));
print load_fiche_titre($langs->trans("ToConsume").' ('.$langs->trans("ForAQuantityOf1").')');
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
@ -501,9 +504,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
{
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<tr><td>TODO...</td></tr>';
}
if (!empty($object->lines))
/*if (!empty($object->lines))
{
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/mrp/tpl');
}
@ -519,7 +524,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
}
} */
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
{
@ -527,6 +532,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
print '</div>';
print "</form>\n";
}

View File

@ -89,8 +89,9 @@ if ($id > 0 || ! empty($ref))
// ------------------------------------------------------------
$linkback = '<a href="' .dol_buildpath('/mrp/mo_list.php', 1) . '?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
$morehtmlref='<div class="refidno">';
$morehtmlref = '';
/*
$morehtmlref='<div class="refidno">';
// Ref customer
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
@ -128,9 +129,9 @@ if ($id > 0 || ! empty($ref))
$morehtmlref.='';
}
}
}*/
}
$morehtmlref.='</div>';
*/
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

View File

@ -326,13 +326,20 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
}
$object->fetchLines();
print '<div class="div-table-responsive-no-min">';
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
{
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<tr><td>TODO...</td></tr>';
//var_dump($object->lines);
}
if (!empty($object->lines))
/*if (!empty($object->lines))
{
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/mrp/tpl');
}
@ -348,7 +355,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
}
}
}*/
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
{

View File

@ -1521,6 +1521,7 @@ div#id-top {
display:none;
<?php } else { ?>
background: rgb(<?php echo $colorbackhmenu1 ?>);
background-image: linear-gradient(-45deg, <?php echo colorAdjustBrightness(colorArrayToHex(colorStringToArray($colorbackhmenu1)), '5'); ?>, rgb(<?php echo $colorbackhmenu1 ?>));
<?php } ?>
}