Work on MRP module
This commit is contained in:
parent
583aa3c619
commit
c0ef3b46ad
@ -532,7 +532,7 @@ class BOM extends CommonObject
|
||||
$error = 0;
|
||||
|
||||
// Protection
|
||||
if ($this->statut == self::STATUS_VALIDATED)
|
||||
if ($this->status == self::STATUS_VALIDATED)
|
||||
{
|
||||
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
|
||||
return 0;
|
||||
|
||||
@ -466,9 +466,11 @@ CREATE TABLE llx_mrp_mo(
|
||||
note_public text,
|
||||
note_private text,
|
||||
date_creation datetime NOT NULL,
|
||||
date_valid datetime NULL,
|
||||
tms timestamp,
|
||||
fk_user_creat integer NOT NULL,
|
||||
fk_user_modif integer,
|
||||
fk_user_valid integer,
|
||||
model_pdf varchar(255),
|
||||
import_key varchar(14),
|
||||
status integer NOT NULL,
|
||||
@ -480,6 +482,9 @@ CREATE TABLE llx_mrp_mo(
|
||||
-- END MODULEBUILDER FIELDS
|
||||
) ENGINE=innodb;
|
||||
|
||||
ALTER TABLE llx_mrp_mo ADD COLUMN date_valid datetime NULL;
|
||||
ALTER TABLE llx_mrp_mo ADD COLUMN fk_user_valid integer;
|
||||
|
||||
ALTER TABLE llx_bom_bom ADD COLUMN model_pdf varchar(255);
|
||||
ALTER TABLE llx_mrp_mo ADD COLUMN model_pdf varchar(255);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
-- Copyright (C) ---Put here your own copyright and developer email---
|
||||
-- Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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
|
||||
@ -26,9 +26,11 @@ CREATE TABLE llx_mrp_mo(
|
||||
note_public text,
|
||||
note_private text,
|
||||
date_creation datetime NOT NULL,
|
||||
date_valid datetime NULL,
|
||||
tms timestamp,
|
||||
fk_user_creat integer NOT NULL,
|
||||
fk_user_modif integer,
|
||||
fk_user_modif integer,
|
||||
fk_user_valid integer,
|
||||
import_key varchar(14),
|
||||
model_pdf varchar(255),
|
||||
status integer NOT NULL,
|
||||
|
||||
@ -50,7 +50,12 @@ BomAndBomLines=Bills Of Material and lines
|
||||
BOMLine=Line of BOM
|
||||
WarehouseForProduction=Warehouse for production
|
||||
CreateMO=Create MO
|
||||
ToConsume=A consommer
|
||||
Manufactured=Fabriqué
|
||||
ToConsume=To consume
|
||||
ToProduce=To produce
|
||||
QtyAlreadyConsumed=Qty already consumed
|
||||
QtyAlreadyProduced=Qty already produced
|
||||
ConsumeAndProduceAll=Consume and Produce All
|
||||
Manufactured=Manufactured
|
||||
TheProductXIsAlreadyTheProductToProduce=The product to add is already the product to produce.
|
||||
ForAQuantityOf1=For a quantity to produce of 1
|
||||
ForAQuantityOf1=For a quantity to produce of 1
|
||||
ConfirmValidateMo=Are you sure you want to validate this Manufacturing Order?
|
||||
@ -514,7 +514,7 @@ class MyObject extends CommonObject
|
||||
$error = 0;
|
||||
|
||||
// Protection
|
||||
if ($this->statut == self::STATUS_VALIDATED)
|
||||
if ($this->status == self::STATUS_VALIDATED)
|
||||
{
|
||||
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
|
||||
return 0;
|
||||
|
||||
@ -499,13 +499,24 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
/*
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
if ($object->status == 1)
|
||||
if ($object->status == $object::STATUS_ENABLED)
|
||||
{
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n";
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n";
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n";
|
||||
}
|
||||
}
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
if ($object->status == $object::STATUS_VALIDATED)
|
||||
{
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close">'.$langs->trans("Cancel").'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen">'.$langs->trans("Re-Open").'</a>'."\n";
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@ -92,10 +92,10 @@ class Mo extends CommonObject
|
||||
*/
|
||||
public $fields = array(
|
||||
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1,),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1',),
|
||||
'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1),
|
||||
'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1', 'noteditable'=>1),
|
||||
'fk_bom' => array('type'=>'integer:Bom:bom/class/bom.class.php:0:t.status=1', 'filter'=>'active=1', 'label'=>'BOM', 'enabled'=>1, 'visible'=>1, 'position'=>33, 'notnull'=>-1, 'index'=>1, 'comment'=>"Original BOM",),
|
||||
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce",),
|
||||
'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce"),
|
||||
'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce",),
|
||||
'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'showoncombobox'=>'1',),
|
||||
'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1', 'label'=>'ThirdParty', 'enabled'=>1, 'visible'=>-1, 'position'=>50, 'notnull'=>-1, 'index'=>1),
|
||||
@ -250,7 +250,7 @@ class Mo extends CommonObject
|
||||
$error++;
|
||||
}
|
||||
|
||||
// Insert lines in mrp_production table
|
||||
// Insert lines in mrp_production table from BOM data
|
||||
if (!$error && $this->fk_bom > 0)
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
|
||||
@ -258,32 +258,52 @@ class Mo extends CommonObject
|
||||
$bom->fetch($this->fk_bom);
|
||||
if ($bom->id > 0)
|
||||
{
|
||||
foreach ($bom->lines as $line)
|
||||
{
|
||||
$moline = new MoLine($this->db);
|
||||
$moline = new MoLine($this->db);
|
||||
|
||||
$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;
|
||||
// Line to produce
|
||||
$moline->fk_mo = $this->id;
|
||||
$moline->qty = $this->qty;
|
||||
$moline->fk_product = $this->fk_product;
|
||||
$moline->role = 'toproduce';
|
||||
$moline->position = 1;
|
||||
|
||||
$resultline = $moline->create($user);
|
||||
if ($resultline <= 0) {
|
||||
$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);
|
||||
}
|
||||
|
||||
// Lines to consume
|
||||
if (! $error) {
|
||||
foreach ($bom->lines as $line)
|
||||
{
|
||||
$moline = new MoLine($this->db);
|
||||
|
||||
$moline->fk_mo = $this->id;
|
||||
$moline->qty = round($line->qty * $this->qty / $bom->efficiency, 2);
|
||||
if ($moline->qty <= 0) {
|
||||
$error++;
|
||||
$this->error = $moline->error;
|
||||
$this->errors = $moline->errors;
|
||||
dol_print_error($this->db, $moline->error, $moline->errors);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -540,6 +560,193 @@ class Mo extends CommonObject
|
||||
return $this->deleteLineCommon($user, $idline, $notrigger);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the reference to the following non used MO depending on the active numbering module
|
||||
* defined into MRP_MO_ADDON
|
||||
*
|
||||
* @param Product $prod Object product
|
||||
* @return string MO free reference
|
||||
*/
|
||||
public function getNextNumRef($prod)
|
||||
{
|
||||
global $langs, $conf;
|
||||
$langs->load("mrp");
|
||||
|
||||
if (!empty($conf->global->MRP_MO_ADDON))
|
||||
{
|
||||
$mybool = false;
|
||||
|
||||
$file = $conf->global->MRP_MO_ADDON.".php";
|
||||
$classname = $conf->global->MRP_MO_ADDON;
|
||||
|
||||
// Include file with class
|
||||
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
|
||||
foreach ($dirmodels as $reldir)
|
||||
{
|
||||
$dir = dol_buildpath($reldir."core/modules/mrp/");
|
||||
|
||||
// Load file with numbering class (if found)
|
||||
$mybool |= @include_once $dir.$file;
|
||||
}
|
||||
|
||||
if ($mybool === false)
|
||||
{
|
||||
dol_print_error('', "Failed to include file ".$file);
|
||||
return '';
|
||||
}
|
||||
|
||||
$obj = new $classname();
|
||||
$numref = $obj->getNextValue($prod, $this);
|
||||
|
||||
if ($numref != "")
|
||||
{
|
||||
return $numref;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = $obj->error;
|
||||
//dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("Error")." ".$langs->trans("Error_MRP_MO_ADDON_NotDefined");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Mo
|
||||
*
|
||||
* @param User $user User making status change
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
* @return int <=0 if OK, 0=Nothing done, >0 if KO
|
||||
*/
|
||||
public function validate($user, $notrigger = 0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
$error = 0;
|
||||
|
||||
// Protection
|
||||
if ($this->status == self::STATUS_VALIDATED)
|
||||
{
|
||||
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mrp->create))
|
||||
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mrp->mrp_advance->validate))))
|
||||
{
|
||||
$this->error='NotEnoughPermissions';
|
||||
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
$now = dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Define new ref
|
||||
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
|
||||
{
|
||||
$this->fetch_product();
|
||||
$num = $this->getNextNumRef($this->product);
|
||||
}
|
||||
else
|
||||
{
|
||||
$num = $this->ref;
|
||||
}
|
||||
$this->newref = $num;
|
||||
|
||||
// Validate
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
|
||||
$sql .= " SET ref = '".$this->db->escape($num)."',";
|
||||
$sql .= " status = ".self::STATUS_VALIDATED.",";
|
||||
$sql .= " date_valid='".$this->db->idate($now)."',";
|
||||
$sql .= " fk_user_valid = ".$user->id;
|
||||
$sql .= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$this->error = $this->db->lasterror();
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error && !$notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
$result = $this->call_trigger('MRP_MO_VALIDATE', $user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$this->oldref = $this->ref;
|
||||
|
||||
// Rename directory if dir was a temporary ref
|
||||
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||
{
|
||||
// Now we rename also files into index
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'mrp/".$this->db->escape($this->newref)."'";
|
||||
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
|
||||
|
||||
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
|
||||
$oldref = dol_sanitizeFileName($this->ref);
|
||||
$newref = dol_sanitizeFileName($num);
|
||||
$dirsource = $conf->mrp->dir_output.'/'.$oldref;
|
||||
$dirdest = $conf->mrp->dir_output.'/'.$newref;
|
||||
if (!$error && file_exists($dirsource))
|
||||
{
|
||||
dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
|
||||
|
||||
if (@rename($dirsource, $dirdest))
|
||||
{
|
||||
dol_syslog("Rename ok");
|
||||
// Rename docs starting with $oldref with $newref
|
||||
$listoffiles = dol_dir_list($conf->mrp->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
||||
foreach ($listoffiles as $fileentry)
|
||||
{
|
||||
$dirsource = $fileentry['name'];
|
||||
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
|
||||
$dirsource = $fileentry['path'].'/'.$dirsource;
|
||||
$dirdest = $fileentry['path'].'/'.$dirdest;
|
||||
@rename($dirsource, $dirdest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set new ref and current status
|
||||
if (!$error)
|
||||
{
|
||||
$this->ref = $num;
|
||||
$this->status = self::STATUS_VALIDATED;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a link to the object card (with optionaly the picto)
|
||||
*
|
||||
@ -824,19 +1031,19 @@ class Mo extends CommonObject
|
||||
{
|
||||
foreach ($this->lines as $line)
|
||||
{
|
||||
if (is_object($hookmanager))
|
||||
/*if (is_object($hookmanager) && (($line->product_type == 9 && !empty($line->special_code)) || !empty($line->fk_parent_line)))
|
||||
{
|
||||
if (empty($line->fk_parent_line))
|
||||
{
|
||||
$parameters = array('line'=>$line, 'i'=>$i);
|
||||
$action = '';
|
||||
$hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
$result = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{*/
|
||||
$this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
|
||||
}
|
||||
//}
|
||||
|
||||
$i++;
|
||||
}
|
||||
@ -873,7 +1080,7 @@ class Mo extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
// If origin BOM line is not a product, but another BOM
|
||||
// If origin MRP line is not a product, but another MRP
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
@ -139,7 +139,7 @@ if (empty($reshook))
|
||||
}
|
||||
$triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record
|
||||
|
||||
// Actions cancel, add, update, delete or clone
|
||||
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
|
||||
|
||||
// Actions when linking object each other
|
||||
@ -361,7 +361,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
$ref = substr($object->ref, 1, 4);
|
||||
if ($ref == 'PROV') {
|
||||
$object->fetch_product();
|
||||
$numref = $object->getNextNumRef($object->thirdparty);
|
||||
$numref = $object->getNextNumRef($object->fk_product);
|
||||
} else {
|
||||
$numref = $object->ref;
|
||||
}
|
||||
@ -487,7 +487,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
if (!empty($object->table_element_line))
|
||||
{
|
||||
// Show object lines
|
||||
$result = $object->getLinesArray();
|
||||
//$result = $object->getLinesArray();
|
||||
$object->fetchLines();
|
||||
|
||||
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
|
||||
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'].'">
|
||||
@ -496,42 +497,61 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
<input type="hidden" name="id" value="' . $object->id.'">
|
||||
';
|
||||
|
||||
if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
|
||||
/*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
|
||||
}
|
||||
}*/
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline'))
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
|
||||
print '<tr><td>TODO...</td></tr>';
|
||||
}
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
|
||||
print '<td></td>';
|
||||
print '</tr>';
|
||||
|
||||
/*if (!empty($object->lines))
|
||||
{
|
||||
$object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/mrp/tpl');
|
||||
}
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("ToConsume").'</td>';
|
||||
print '<td>';
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
$i = 0;
|
||||
foreach($object->lines as $line) {
|
||||
if ($line->role == 'toconsume') {
|
||||
if ($i) print ', ';
|
||||
$tmpproduct = new Product($db);
|
||||
$tmpproduct->fetch($line->fk_product);
|
||||
print $tmpproduct->getNomUrl(1);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Form to add new line
|
||||
if ($object->status == 0 && $permissiontoadd && $action != 'selectlines')
|
||||
{
|
||||
if ($action != 'editline')
|
||||
{
|
||||
// Add products/services form
|
||||
$object->formAddObjectLine(1, $mysoc, $soc, '/mrp/tpl');
|
||||
print '<tr class="oddeven">';
|
||||
print '<td>'.$langs->trans("ToProduce").'</td>';
|
||||
print '<td>';
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
$i = 0;
|
||||
foreach($object->lines as $line) {
|
||||
if ($line->role == 'toproduce') {
|
||||
if ($i) print ', ';
|
||||
$tmpproduct = new Product($db);
|
||||
$tmpproduct->fetch($line->fk_product);
|
||||
print $tmpproduct->getNomUrl(1);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$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'))
|
||||
{
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
|
||||
print "</form>\n";
|
||||
}
|
||||
@ -551,22 +571,24 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
//print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
|
||||
|
||||
// Back to draft
|
||||
if ($object->status == $object::STATUS_VALIDATED)
|
||||
/*if ($object->status == $object::STATUS_VALIDATED)
|
||||
{
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=setdraft">'.$langs->trans("SetToDraft").'</a>';
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// Modify
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
|
||||
if ($object->status == $object::STATUS_DRAFT) {
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Validate
|
||||
@ -591,10 +613,23 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->fk_soc.'&action=clone&object=mo">'.$langs->trans("ToClone").'</a>';
|
||||
}
|
||||
|
||||
// Cancel
|
||||
if ($permissiontoadd)
|
||||
{
|
||||
if ($object->status == $object::STATUS_VALIDATED)
|
||||
{
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes">'.$langs->trans("Cancel").'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes">'.$langs->trans("Re-Open").'</a>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Delete (need delete permission, or if draft, just need create/modify permission)
|
||||
if ($permissiontodelete)
|
||||
{
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete">'.$langs->trans('Delete').'</a>'."\n";
|
||||
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete">'.$langs->trans('Delete').'</a>'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -99,6 +99,7 @@ $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_
|
||||
$permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
|
||||
$upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
|
||||
|
||||
$permissiontoproduce = $permissiontoadd;
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@ -305,6 +306,49 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '<div class="tabsAction">';
|
||||
|
||||
$parameters = array();
|
||||
// Note that $action and $object may be modified by hook
|
||||
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
|
||||
if (empty($reshook)) {
|
||||
// Consume
|
||||
|
||||
if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
|
||||
if ($permissiontoproduce) {
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consume">'.$langs->trans('Consume').'</a>';
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('Consume').'</a>';
|
||||
}
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateFirst").'">'.$langs->trans('Consume').'</a>';
|
||||
}
|
||||
|
||||
// Produce
|
||||
if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
|
||||
if ($permissiontoproduce) {
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=produce">'.$langs->trans('Produce').'</a>';
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('Produce').'</a>';
|
||||
}
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateFirst").'">'.$langs->trans('Produce').'</a>';
|
||||
}
|
||||
|
||||
// ConsumeAndProduceAll
|
||||
if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
|
||||
if ($permissiontoproduce) {
|
||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeandproduceall">'.$langs->trans('ConsumeAndProduceAll').'</a>';
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
|
||||
}
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateFirst").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
/*
|
||||
* Lines
|
||||
@ -313,7 +357,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
if (!empty($object->table_element_line))
|
||||
{
|
||||
// Show object lines
|
||||
$result = $object->getLinesArray();
|
||||
//$result = $object->getLinesArray();
|
||||
$object->fetchLines();
|
||||
|
||||
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#addline' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
|
||||
<input type="hidden" name="token" value="' . $_SESSION ['newtoken'].'">
|
||||
@ -326,16 +371,44 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
|
||||
}
|
||||
|
||||
$object->fetchLines();
|
||||
print '<div class="fichecenter">';
|
||||
print '<div class="fichehalfleft">';
|
||||
print '<div class="clearboth"></div>';
|
||||
|
||||
print load_fiche_titre($langs->trans('Consumption'), '', '');
|
||||
|
||||
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 '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Product").'</td>';
|
||||
print '<td>'.$langs->trans("Qty").'</td>';
|
||||
print '<td>'.$langs->trans("QtyAlreadyConsumed").'</td>';
|
||||
/*print '<td>'.$langs->trans("Date").'</td>';
|
||||
print '<td>'.$langs->trans("Batch").'</td>';*/
|
||||
print '</tr>';
|
||||
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
foreach($object->lines as $line) {
|
||||
if ($line->role == 'toconsume') {
|
||||
print '<tr>';
|
||||
$tmpproduct = new Product($db);
|
||||
$tmpproduct->fetch($line->fk_product);
|
||||
print '<td>'.$tmpproduct->getNomUrl(1).'</td>';
|
||||
print '<td>'.$line->qty.'</td>';
|
||||
$alreadyconsumed = 0;
|
||||
print '<td>'.$alreadyconsumed.'</td>';
|
||||
/*print '<td>'.'</td>';
|
||||
print '<td>'.'</td>';*/
|
||||
print '</tr>';
|
||||
|
||||
print '<tr><td>TODO...</td></tr>';
|
||||
// Show detailed of already consumed
|
||||
//$arrayoflines = $line->fetchLinesLinked('consumed');
|
||||
|
||||
//var_dump($object->lines);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*if (!empty($object->lines))
|
||||
@ -356,10 +429,53 @@ 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>';
|
||||
print '</div>';
|
||||
|
||||
print '</div>';
|
||||
print '<div class="fichehalfright">';
|
||||
print '<div class="clearboth"></div>';
|
||||
|
||||
print load_fiche_titre($langs->trans('Production'), '', '');
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Product").'</td>';
|
||||
print '<td>'.$langs->trans("Qty").'</td>';
|
||||
print '<td>'.$langs->trans("QtyAlreadyProduced").'</td>';
|
||||
/*print '<td>'.$langs->trans("Date").'</td>';
|
||||
print '<td>'.$langs->trans("Batch").'</td>';*/
|
||||
print '</tr>';
|
||||
|
||||
if (!empty($object->lines))
|
||||
{
|
||||
print '</table>';
|
||||
foreach($object->lines as $line) {
|
||||
if ($line->role == 'toproduce') {
|
||||
print '<tr>';
|
||||
$tmpproduct = new Product($db);
|
||||
$tmpproduct->fetch($line->fk_product);
|
||||
print '<td>'.$tmpproduct->getNomUrl(1).'</td>';
|
||||
print '<td>'.$line->qty.'</td>';
|
||||
$alreadyconsumed = 0;
|
||||
print '<td>'.$alreadyconsumed.'</td>';
|
||||
/*print '<td>'.'</td>';
|
||||
print '<td>'.'</td>';*/
|
||||
print '</tr>';
|
||||
|
||||
// Show detailed of already consumed
|
||||
//$arrayoflines = $line->fetchLinesLinked('consumed');
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
print '</div>';
|
||||
print '</div>';
|
||||
|
||||
print "</form>\n";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user