--- /tmp/dsg/dolibarr/htdocs/mrp/class/github_19.0.3_api_mos.class.php +++ /tmp/dsg/dolibarr/htdocs/mrp/class/client_api_mos.class.php @@ -25 +25 @@ - * \file htdocs/mrp/class/api_mos.class.php + * \file mrp/class/api_mo.class.php @@ -58,2 +58,2 @@ - * @param int $id ID of MO - * @return Object Object with cleaned properties + * @param int $id ID of MO + * @return array|mixed data without useless information @@ -62 +62 @@ - * @throws RestException + * @throws RestException @@ -88,4 +88,4 @@ - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number @@ -93 +92,0 @@ - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names @@ -98 +97 @@ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '') + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') @@ -102,4 +100,0 @@ - if (!DolibarrApiAccess::$user->rights->mrp->read) { - throw new RestException(401); - } - @@ -107 +102 @@ - $tmpobject = new Mo($this->db); + $tmpobject = new Mo($db); @@ -115,3 +110 @@ - if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) { - $search_sale = DolibarrApiAccess::$user->id; - } + if ($restrictonsocid && !DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; @@ -120,8 +113,4 @@ - if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) { - $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) - } - $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." AS t LEFT JOIN ".MAIN_DB_PREFIX.$tmpobject->table_element."_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - - if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - } + if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + $sql .= " FROM ".MAIN_DB_PREFIX.$tmpobject->table_element." as t"; + + if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale @@ -134,12 +123,4 @@ - if ($tmpobject->ismultientitymanaged) { - $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')'; - } - if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) { - $sql .= " AND t.fk_soc = sc.fk_soc"; - } - if ($restrictonsocid && $socid) { - $sql .= " AND t.fk_soc = ".((int) $socid); - } - if ($restrictonsocid && $search_sale > 0) { - $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale - } + if ($tmpobject->ismultientitymanaged) $sql .= ' AND t.entity IN ('.getEntity($tmpobject->element).')'; + if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; + if ($restrictonsocid && $socid) $sql .= " AND t.fk_soc = ".$socid; + if ($restrictonsocid && $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale @@ -147,8 +128,9 @@ - if ($restrictonsocid && $search_sale > 0) { - $sql .= " AND sc.fk_user = ".((int) $search_sale); - } - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); + if ($restrictonsocid && $search_sale > 0) + { + $sql .= " AND sc.fk_user = ".$search_sale; + } + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); @@ -156,3 +138,5 @@ - } - - $sql .= $this->db->order($sortfield, $sortorder); + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); @@ -160 +144,2 @@ - if ($page < 0) { + if ($page < 0) + { @@ -165,6 +150,7 @@ - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - if ($result) { - $num = $this->db->num_rows($result); + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); @@ -172,3 +158,4 @@ - while ($i < $num) { - $obj = $this->db->fetch_object($result); - $tmp_object = new Mo($this->db); + while ($i < $num) + { + $obj = $db->fetch_object($result); + $tmp_object = new Mo($db); @@ -176 +163 @@ - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($tmp_object), $properties); + $obj_ret[] = $this->_cleanObjectDatas($tmp_object); @@ -180 +167,2 @@ - } else { + } + else { @@ -183 +171,3 @@ - + if (!count($obj_ret)) { + throw new RestException(404, 'No MO found'); + } @@ -202,6 +191,0 @@ - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->mo->context['caller'] = $request_data['caller']; - continue; - } - @@ -210,3 +193,0 @@ - - $this->checkRefNumbering(); - @@ -243,9 +224 @@ - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->mo->context['caller'] = $request_data['caller']; - continue; - } - + if ($field == 'id') continue; @@ -255,3 +228,2 @@ - $this->checkRefNumbering(); - - if ($this->mo->update(DolibarrApiAccess::$user) > 0) { + if ($this->mo->update($id, DolibarrApiAccess::$user) > 0) + { @@ -259 +231,3 @@ - } else { + } + else + { @@ -284 +258,2 @@ - if (!$this->mo->delete(DolibarrApiAccess::$user)) { + if (!$this->mo->delete(DolibarrApiAccess::$user)) + { @@ -297,612 +271,0 @@ - /** - * Produce and consume all - * - * - If arraytoconsume and arraytoproduce are both filled, this fill an empty MO with the lines to consume and produce and record the consumption and production. - * - If arraytoconsume and arraytoproduce are not provided, it consumes and produces all existing lines. - * - * Example: - * { - * "inventorylabel": "Produce and consume using API", - * "inventorycode": "PRODUCEAPI-YY-MM-DD", - * "autoclose": 1, - * "arraytoconsume": [ - * "objectid": 123, -- ID_of_product - * "qty": "2", - * "fk_warehouse": "789" - * ], - * "arraytoproduce": [ - * "objectid": 456, -- ID_of_product - * "qty": "1", - * "fk_warehouse": "789" - * ] - * } - * - * @param int $id ID of state - * @param array $request_data Request datas - * - * @url POST {id}/produceandconsumeall - * - * @return int ID of MO - */ - public function produceAndConsumeAll($id, $request_data = null) - { - global $langs; - - $error = 0; - - if (!DolibarrApiAccess::$user->hasRight("mrp", "write")) { - throw new RestException(403, 'Not enough permission'); - } - $result = $this->mo->fetch($id); - if (!$result) { - throw new RestException(404, 'MO not found'); - } - - if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) { - throw new RestException(405, 'Error bad status of MO'); - } - - // Code for consume and produce... - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; - require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php'; - - $stockmove = new MouvementStock($this->db); - - $labelmovement = ''; - $codemovement = ''; - $autoclose = 1; - $arraytoconsume = array(); - $arraytoproduce = array(); - - foreach ($request_data as $field => $value) { - if ($field == 'inventorylabel') { - $labelmovement = $value; - } - if ($field == 'inventorycode') { - $codemovement = $value; - } - if ($field == 'autoclose') { - $autoclose = $value; - } - if ($field == 'arraytoconsume') { - $arraytoconsume = $value; - } - if ($field == 'arraytoproduce') { - $arraytoproduce = $value; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $stockmove->context['caller'] = $request_data['caller']; - continue; - } - } - - if (empty($labelmovement)) { - throw new RestException(500, "Field inventorylabel not provided"); - } - if (empty($codemovement)) { - throw new RestException(500, "Field inventorycode not provided"); - } - - $consumptioncomplete = true; - $productioncomplete = true; - - if (!empty($arraytoconsume) && !empty($arraytoproduce)) { - $pos = 0; - $arrayofarrayname = array("arraytoconsume","arraytoproduce"); - foreach ($arrayofarrayname as $arrayname) { - foreach (${$arrayname} as $value) { - $tmpproduct = new Product($this->db); - if (empty($value["objectid"])) { - throw new RestException(500, "Field objectid required in ".$arrayname); - } - $tmpproduct->fetch($value["qty"]); - if (empty($value["qty"])) { - throw new RestException(500, "Field qty required in ".$arrayname); - } - if ($value["qty"] != 0) { - $qtytoprocess = $value["qty"]; - if (isset($value["fk_warehouse"])) { // If there is a warehouse to set - if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set. - $error++; - throw new RestException(500, "Field fk_warehouse must be > 0 in ".$arrayname); - } - if ($tmpproduct->status_batch) { - $error++; - throw new RestException(500, "Product ".$tmpproduct->ref."must be in batch"); - } - } - $idstockmove = 0; - if (!$error && $value["fk_warehouse"] > 0) { - // Record consumption to do and stock movement - $id_product_batch = 0; - - $stockmove->setOrigin($this->mo->element, $this->mo->id); - - if ($arrayname == 'arraytoconsume') { - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $value["objectid"]; - $moline->fk_warehouse = $value["fk_warehouse"]; - $moline->qty = $qtytoprocess; - $moline->batch = $tmpproduct->status_batch; - $moline->role = 'toproduce'; - $moline->fk_mrp_production = ""; - $moline->fk_stock_movement = $idstockmove; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - $error++; - throw new RestException(500, $moline->error); - } - $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } else { - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $value["objectid"]; - $moline->fk_warehouse = $value["fk_warehouse"]; - $moline->qty = $qtytoprocess; - $moline->batch = $tmpproduct->status_batch; - $moline->role = 'toconsume'; - $moline->fk_mrp_production = ""; - $moline->fk_stock_movement = $idstockmove; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - $error++; - throw new RestException(500, $moline->error); - } - $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $value["objectid"], $value["fk_warehouse"], $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } - if ($idstockmove < 0) { - $error++; - throw new RestException(500, $stockmove->error); - } - } - if (!$error) { - // Record consumption done - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $value["objectid"]; - $moline->fk_warehouse = $value["fk_warehouse"]; - $moline->qty = $qtytoprocess; - $moline->batch = $tmpproduct->status_batch; - if ($arrayname == "arraytoconsume") { - $moline->role = 'consumed'; - } else { - $moline->role = 'produced'; - } - $moline->fk_mrp_production = ""; - $moline->fk_stock_movement = $idstockmove; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - $error++; - throw new RestException(500, $moline->error); - } - - $pos++; - } - } - } - } - if (!$error) { - if ($autoclose <= 0) { - $consumptioncomplete = false; - $productioncomplete = false; - } - } - } else { - $pos = 0; - foreach ($this->mo->lines as $line) { - if ($line->role == 'toconsume') { - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($line->fk_product); - if ($line->qty != 0) { - $qtytoprocess = $line->qty; - if (isset($line->fk_warehouse)) { // If there is a warehouse to set - if (!($line->fk_warehouse > 0)) { // If there is no warehouse set. - $langs->load("errors"); - $error++; - throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref)); - } - if ($tmpproduct->status_batch) { - $langs->load("errors"); - $error++; - throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref)); - } - } - $idstockmove = 0; - if (!$error && $line->fk_warehouse > 0) { - // Record stock movement - $id_product_batch = 0; - $stockmove->origin_type = 'mo'; - $stockmove->origin_id = $this->mo->id; - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } else { - $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } - if ($idstockmove < 0) { - $error++; - throw new RestException(500, $stockmove->error); - } - } - if (!$error) { - // Record consumption - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $line->fk_product; - $moline->fk_warehouse = $line->fk_warehouse; - $moline->qty = $qtytoprocess; - $moline->batch = $tmpproduct->status_batch; - $moline->role = 'consumed'; - $moline->fk_mrp_production = $line->id; - $moline->fk_stock_movement = $idstockmove; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - $error++; - throw new RestException(500, $moline->error); - } - - $pos++; - } - } - } - } - $pos = 0; - foreach ($this->mo->lines as $line) { - if ($line->role == 'toproduce') { - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($line->fk_product); - if ($line->qty != 0) { - $qtytoprocess = $line->qty; - if (isset($line->fk_warehouse)) { // If there is a warehouse to set - if (!($line->fk_warehouse > 0)) { // If there is no warehouse set. - $langs->load("errors"); - $error++; - throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref)); - } - if ($tmpproduct->status_batch) { - $langs->load("errors"); - $error++; - throw new RestException(500, $langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref)); - } - } - $idstockmove = 0; - if (!$error && $line->fk_warehouse > 0) { - // Record stock movement - $id_product_batch = 0; - $stockmove->origin_type = 'mo'; - $stockmove->origin_id = $this->mo->id; - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } else { - $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $line->fk_product, $line->fk_warehouse, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } - if ($idstockmove < 0) { - $error++; - throw new RestException(500, $stockmove->error); - } - } - if (!$error) { - // Record consumption - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $line->fk_product; - $moline->fk_warehouse = $line->fk_warehouse; - $moline->qty = $qtytoprocess; - $moline->batch = $tmpproduct->status_batch; - $moline->role = 'produced'; - $moline->fk_mrp_production = $line->id; - $moline->fk_stock_movement = $idstockmove; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - $error++; - throw new RestException(500, $moline->error); - } - - $pos++; - } - } - } - } - - if (!$error) { - if ($autoclose > 0) { - foreach ($this->mo->lines as $line) { - if ($line->role == 'toconsume') { - $arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id); - $alreadyconsumed = 0; - foreach ($arrayoflines as $line2) { - $alreadyconsumed += $line2['qty']; - } - - if ($alreadyconsumed < $line->qty) { - $consumptioncomplete = false; - } - } - if ($line->role == 'toproduce') { - $arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id); - $alreadyproduced = 0; - foreach ($arrayoflines as $line2) { - $alreadyproduced += $line2['qty']; - } - - if ($alreadyproduced < $line->qty) { - $productioncomplete = false; - } - } - } - } else { - $consumptioncomplete = false; - $productioncomplete = false; - } - } - } - - // Update status of MO - dol_syslog("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete); - //var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete); - if ($consumptioncomplete && $productioncomplete) { - $result = $this->mo->setStatut(Mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED'); - } else { - $result = $this->mo->setStatut(Mo::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED'); - } - if ($result <= 0) { - throw new RestException(500, $this->mo->error); - } - - return $this->mo->id; - } - - /** - * Produce and consume - * - * Example: - * { - * "inventorylabel": "Produce and consume using API", - * "inventorycode": "PRODUCEAPI-YY-MM-DD", - * "autoclose": 1, - * "arraytoconsume": [ - * { - * "objectid": "123", -- rowid of MoLine - * "qty": "2", - * "fk_warehouse": "789" -- "0" or empty, if stock change is disabled. - * } - * ], - * "arraytoproduce": [ - * { - * "objectid": "456", -- rowid of MoLine - * "qty": "1", - * "fk_warehouse": "789", - * "pricetoproduce": "12.3" -- optional - * } - * ] - * } - * - * @param int $id ID of state - * @param array $request_data Request datas - * - * @url POST {id}/produceandconsume - * - * @return int ID of MO - */ - public function produceAndConsume($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight("mrp", "write")) { - throw new RestException(403, 'Not enough permission'); - } - $result = $this->mo->fetch($id); - if (!$result) { - throw new RestException(404, 'MO not found'); - } - - if ($this->mo->status != Mo::STATUS_VALIDATED && $this->mo->status != Mo::STATUS_INPROGRESS) { - throw new RestException(405, 'Error bad status of MO'); - } - - // Code for consume and produce... - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; - require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php'; - - $stockmove = new MouvementStock($this->db); - - $labelmovement = ''; - $codemovement = ''; - $autoclose = 1; - $arraytoconsume = array(); - $arraytoproduce = array(); - - foreach ($request_data as $field => $value) { - if ($field == 'inventorylabel') { - $labelmovement = $value; - } - if ($field == 'inventorycode') { - $codemovement = $value; - } - if ($field == 'autoclose') { - $autoclose = $value; - } - if ($field == 'arraytoconsume') { - $arraytoconsume = $value; - } - if ($field == 'arraytoproduce') { - $arraytoproduce = $value; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $stockmove->context['caller'] = $request_data['caller']; - continue; - } - } - - if (empty($labelmovement)) { - throw new RestException(500, "Field inventorylabel not provided"); - } - if (empty($codemovement)) { - throw new RestException(500, "Field inventorycode not provided"); - } - - $this->db->begin(); - - $pos = 0; - $arrayofarrayname = array("arraytoconsume","arraytoproduce"); - foreach ($arrayofarrayname as $arrayname) { - foreach (${$arrayname} as $value) { - if (empty($value["objectid"])) { - throw new RestException(500, "Field objectid required in " . $arrayname); - } - - $molinetoprocess = new MoLine($this->db); - $tmpmolineid = $molinetoprocess->fetch($value["objectid"]); - if ($tmpmolineid <= 0) { - throw new RestException(500, "MoLine with rowid " . $value["objectid"] . " not exist."); - } - - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($molinetoprocess->fk_product); - if ($tmpproduct->status_batch) { - throw new RestException(500, "Product " . $tmpproduct->ref . " must be in batch, this API can't handle it currently."); - } - - if (empty($value["qty"]) && $value["qty"] != 0) { - throw new RestException(500, "Field qty with lower or higher then 0 required in " . $arrayname); - } - $qtytoprocess = $value["qty"]; - - $fk_warehousetoprocess = 0; - if ($molinetoprocess->disable_stock_change == false) { - if (isset($value["fk_warehouse"])) { // If there is a warehouse to set - if (!($value["fk_warehouse"] > 0)) { // If there is no warehouse set. - throw new RestException(500, "Field fk_warehouse required in " . $arrayname); - } - } - $fk_warehousetoprocess = (int) $value["fk_warehouse"]; - } - - $pricetoproduce = 0; - if (isset($value["pricetoproduce"])) { // If there is a price to produce set. - if ($value["pricetoproduce"] > 0) { // Only use prices grater then 0. - $pricetoproduce = $value["pricetoproduce"]; - } - } - - $pos = 0; - $idstockmove = 0; - - if ($molinetoprocess->disable_stock_change == false) { - // Record stock movement - $id_product_batch = 0; - $stockmove->origin_type = 'mo'; - $stockmove->origin_id = $this->mo->id; - if ($arrayname == "arraytoconsume") { - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } else { - $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } - } else { - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->reception(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, $pricetoproduce, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } else { - $idstockmove = $stockmove->livraison(DolibarrApiAccess::$user, $molinetoprocess->fk_product, $fk_warehousetoprocess, $qtytoprocess, 0, $labelmovement, dol_now(), '', '', $tmpproduct->status_batch, $id_product_batch, $codemovement); - } - } - if ($idstockmove <= 0) { - throw new RestException(500, $stockmove->error); - } - } - - // Record consumption - $moline = new MoLine($this->db); - $moline->fk_mo = $this->mo->id; - $moline->position = $pos; - $moline->fk_product = $tmpproduct->id; - $moline->fk_warehouse = $idstockmove > 0 ? $fk_warehousetoprocess : null; - $moline->qty = $qtytoprocess; - $moline->batch = ''; - $moline->fk_mrp_production = $molinetoprocess->id; - $moline->fk_stock_movement = $idstockmove > 0 ? $idstockmove : null; - $moline->fk_user_creat = DolibarrApiAccess::$user->id; - - if ($arrayname == "arraytoconsume") { - $moline->role = 'consumed'; - } else { - $moline->role = 'produced'; - } - - $resultmoline = $moline->create(DolibarrApiAccess::$user); - if ($resultmoline <= 0) { - throw new RestException(500, $moline->error); - } - } - } - - $consumptioncomplete = true; - $productioncomplete = true; - - if ($autoclose > 0) { - // Refresh Lines after consumptions. - $this->mo->fetchLines(); - - foreach ($this->mo->lines as $line) { - if ($line->role == 'toconsume') { - $arrayoflines = $this->mo->fetchLinesLinked('consumed', $line->id); - $alreadyconsumed = 0; - foreach ($arrayoflines as $line2) { - $alreadyconsumed += $line2['qty']; - } - - if ($alreadyconsumed < $line->qty) { - $consumptioncomplete = false; - } - } - if ($line->role == 'toproduce') { - $arrayoflines = $this->mo->fetchLinesLinked('produced', $line->id); - $alreadyproduced = 0; - foreach ($arrayoflines as $line2) { - $alreadyproduced += $line2['qty']; - } - - if ($alreadyproduced < $line->qty) { - $productioncomplete = false; - } - } - } - } else { - $consumptioncomplete = false; - $productioncomplete = false; - } - - // Update status of MO - dol_syslog("consumptioncomplete = " . $consumptioncomplete . " productioncomplete = " . $productioncomplete); - //var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete); - if ($consumptioncomplete && $productioncomplete) { - $result = $this->mo->setStatut(Mo::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED'); - } else { - $result = $this->mo->setStatut(Mo::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED'); - } - if ($result <= 0) { - throw new RestException(500, $this->mo->error); - } - - $this->db->commit(); - return $this->mo->id; - } - - @@ -913,2 +276,2 @@ - * @param Object $object Object to clean - * @return Object Object with cleaned properties + * @param object $object Object to clean + * @return array Array of cleaned object properties @@ -960 +323,2 @@ - for ($i = 0; $i < $nboflines; $i++) { + for ($i = 0; $i < $nboflines; $i++) + { @@ -983,4 +347,2 @@ - if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) { - continue; // Not a mandatory field - } - if (!isset($data[$field])) { + if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) continue; // Not a mandatory field + if (!isset($data[$field])) @@ -988,2 +350 @@ - } - $myobject[$field] = $data[$field]; + $myobject[$field] = $data[$field]; @@ -993,23 +353,0 @@ - - /** - * Validate the ref field and get the next Number if it's necessary. - * - * @return void - */ - private function checkRefNumbering(): void - { - $ref = substr($this->mo->ref, 1, 4); - if ($this->mo->status > 0 && $ref == 'PROV') { - throw new RestException(400, "Wrong naming scheme '(PROV%)' is only allowed on 'DRAFT' status. For automatic increment use 'auto' on the 'ref' field."); - } - - if (strtolower($this->mo->ref) == 'auto') { - if (empty($this->mo->id) && $this->mo->status == 0) { - $this->mo->ref = ''; // 'ref' will auto incremented with '(PROV' + newID + ')' - } else { - $this->mo->fetch_product(); - $numref = $this->mo->getNextNumRef($this->mo->product); - $this->mo->ref = $numref; - } - } - } --- /tmp/dsg/dolibarr/htdocs/mrp/class/github_19.0.3_mo.class.php +++ /tmp/dsg/dolibarr/htdocs/mrp/class/client_mo.class.php @@ -4 +4 @@ - * Copyright (C) 2023 Frédéric France + * Copyright (C) ---Put here your own copyright and developer email--- @@ -17 +17 @@ - * along with this program. If not, see . + * along with this program. If not, see . @@ -28 +28,2 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; @@ -48 +49 @@ - public $ismultientitymanaged = 1; + public $ismultientitymanaged = 0; @@ -68,2 +69,3 @@ - /** - * 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') + + /** + * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') @@ -72,3 +74,3 @@ - * 'picto' is code of a picto to show before value in forms - * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM) - * 'position' is the sort order of field. + * 'enabled' is a condition when the field must be managed. + * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). Using a negative value means field is not shown by default on list but can be selected for viewing) + * 'noteditable' says if field is not editable (1 or 0) @@ -76,3 +78 @@ - * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) - * 'noteditable' says if field is not editable (1 or 0) - * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. + * 'default' is a default value for creation (can still be replaced by the global setup of default values) @@ -80,0 +81 @@ + * 'position' is the sort order of field. @@ -83,2 +84,3 @@ - * 'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'maxwidth200', 'wordbreak', 'tdoverflowmax200' - * 'help' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. + * 'css' is the CSS style to use on field. For example: 'maxwidth200' + * 'help' is a string visible as a tooltip on field + * 'comment' is not used. You can store here any text of your choice. It is not used by application. @@ -86,8 +88,4 @@ - * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") - * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. - * 'comment' is not used. You can store here any text of your choice. It is not used by application. - * - * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. - */ - + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + */ + + // BEGIN MODULEBUILDER PROPERTIES @@ -98 +96 @@ - 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",), + 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",), @@ -101,9 +99,8 @@ - 'fk_bom' => array('type'=>'integer:Bom:bom/class/bom.class.php:0:(t.status:=:1)', 'filter'=>'active=1', 'label'=>'BOM', 'enabled'=>'$conf->bom->enabled', 'visible'=>1, 'position'=>33, 'notnull'=>-1, 'index'=>1, 'comment'=>"Original BOM", 'css'=>'minwidth100 maxwidth500', 'csslist'=>'tdoverflowmax150', 'picto'=>'bom'), - 'mrptype' => array('type'=>'integer', 'label'=>'Type', 'enabled'=>1, 'visible'=>1, 'position'=>34, 'notnull'=>1, 'default'=>'0', 'arrayofkeyval'=>array(0=>'Manufacturing', 1=>'Disassemble'), 'css'=>'minwidth150', 'csslist'=>'minwidth150 center'), - 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>'isModEnabled("product")', 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce", 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax100', 'picto'=>'product'), - 'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce", 'css'=>'width75', 'default'=>1, 'isameasure'=>1), - 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'showoncombobox'=>'2', 'css'=>'maxwidth300', 'csslist'=>'tdoverflowmax200', 'alwayseditable'=>1), - 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1', 'label'=>'ThirdParty', 'picto'=>'company', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'css'=>'maxwidth400', 'csslist'=>'tdoverflowmax150'), - 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Project', 'picto'=>'project', 'enabled'=>'$conf->project->enabled', 'visible'=>-1, 'position'=>51, 'notnull'=>-1, 'index'=>1, 'css'=>'minwidth200 maxwidth400', 'csslist'=>'tdoverflowmax100'), - 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php:0', 'label'=>'WarehouseForProduction', 'picto'=>'stock', 'enabled'=>'isModEnabled("stock")', 'visible'=>1, 'position'=>52, 'css'=>'maxwidth400', 'csslist'=>'tdoverflowmax200'), - 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61, 'notnull'=>-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", 'css'=>'maxwidth300'), + '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", 'css'=>'maxwidth300'), + 'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce", 'css'=>'width75', 'isameasure'=>1), + '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, 'css'=>'maxwidth300'), + 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Project', 'enabled'=>1, 'visible'=>-1, 'position'=>51, 'notnull'=>-1, 'index'=>1,), + 'fk_warehouse' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php:0', 'label'=>'WarehouseForProduction', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'css'=>'maxwidth300'), + 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61, 'notnull'=>-1,), @@ -112,6 +109,6 @@ - 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>1,), - 'date_valid' => array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-2, 'position'=>502,), - 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid', 'csslist'=>'tdoverflowmax100'), - 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1, 'csslist'=>'tdoverflowmax100'), - 'date_start_planned' => array('type'=>'datetime', 'label'=>'DateStartPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>55, 'notnull'=>-1, 'index'=>1, 'help'=>'KeepEmptyForAsap', 'alwayseditable'=>1, 'csslist'=>'nowraponall'), - 'date_end_planned' => array('type'=>'datetime', 'label'=>'DateEndPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>56, 'notnull'=>-1, 'index'=>1, 'alwayseditable'=>1, 'csslist'=>'nowraponall'), + 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'position'=>501, 'notnull'=>-1,), + 'date_valid' => array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>2, 'position'=>502,), + 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>510, 'notnull'=>1, 'foreignkey'=>'user.rowid',), + 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'position'=>511, 'notnull'=>-1,), + 'date_start_planned' => array('type'=>'datetime', 'label'=>'DateStartPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>55, 'notnull'=>-1, 'index'=>1, 'help'=>'KeepEmptyForAsap'), + 'date_end_planned' => array('type'=>'datetime', 'label'=>'DateEndPlannedMo', 'enabled'=>1, 'visible'=>1, 'position'=>56, 'notnull'=>-1, 'index'=>1,), @@ -120,2 +117 @@ - 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>2, 'position'=>1000, 'default'=>0, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '2'=>'InProgress', '3'=>'StatusMOProduced', '9'=>'Canceled')), - 'fk_parent_line' => array('type'=>'integer:MoLine:mrp/class/mo.class.php', 'label'=>'ParentMo', 'enabled'=>1, 'visible'=>0, 'position'=>1020, 'default'=>0, 'notnull'=>0, 'index'=>1,'showoncombobox'=>0), + 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>2, 'position'=>1000, 'default'=>0, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validated', '2'=>'InProgress', '3'=>'StatusMOProduced', '9'=>'Canceled')), @@ -123,0 +120 @@ + public $ref; @@ -125,6 +121,0 @@ - public $ref; - - /** - * @var int mrptype - */ - public $mrptype; @@ -135 +125,0 @@ - public $socid; @@ -152,8 +142 @@ - /** - * @var integer|string date_validation - */ - public $date_valid; - - /** - * @var integer|string date_validation - */ + @@ -161 +143,0 @@ - @@ -166,4 +147,0 @@ - - /** - * @var int ID of product - */ @@ -173,5 +150,0 @@ - * @var Product product object - */ - public $product; - - /** @@ -187,3 +160 @@ - /** - * @var int ID bom - */ + @@ -191,9 +161,0 @@ - - /** - * @var Bom bom - */ - public $bom; - - /** - * @var int ID project - */ @@ -201,6 +163 @@ - - /** - * @var double New quantity. When we update the quantity to produce, we set this to save old value before calling the ->update that call the updateProduction that need this - * to recalculate all the quantities in lines to consume and produce. - */ - public $oldQty; + // END MODULEBUILDER PROPERTIES @@ -212,6 +169,6 @@ - * @var string Name of subtable line - */ - public $table_element_line = 'mrp_production'; - - /** - * @var string Field with ID of parent key if this field has a parent + * @var int Name of subtable line + */ + public $table_element_line = 'mo_production'; + + /** + * @var int Field with ID of parent key if this field has a parent @@ -222 +179 @@ - * @var string Name of subtable class that manage subtable lines + * @var int Name of subtable class that manage subtable lines @@ -241,14 +197,0 @@ - /** - * @var MoLine MO line - */ - public $line = array(); - - /** - * @var int ID of parent line - */ - public $fk_parent_line; - - /** - * @var array tpl - */ - public $tpl = array(); @@ -268,6 +211,2 @@ - if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) { - $this->fields['rowid']['visible'] = 0; - } - if (!isModEnabled('multicompany') && isset($this->fields['entity'])) { - $this->fields['entity']['enabled'] = 0; - } + 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; @@ -276,2 +215,4 @@ - foreach ($this->fields as $key => $val) { - if (isset($val['enabled']) && empty($val['enabled'])) { + foreach ($this->fields as $key => $val) + { + if (isset($val['enabled']) && empty($val['enabled'])) + { @@ -283,3 +224,6 @@ - foreach ($this->fields as $key => $val) { - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { - foreach ($val['arrayofkeyval'] as $key2 => $val2) { + foreach ($this->fields as $key => $val) + { + if (is_array($val['arrayofkeyval'])) + { + foreach ($val['arrayofkeyval'] as $key2 => $val2) + { @@ -297 +241 @@ - * @return int Return integer <=0 if KO, Id of created object if OK + * @return int <=0 if KO, Id of created object if OK @@ -300,0 +245,2 @@ + global $conf; + @@ -304,12 +249,0 @@ - // If kits feature is enabled and we don't allow kits into BOM and MO, we check that the product is not a kit/virtual product - if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && !getDolGlobalString('ALLOW_USE_KITS_INTO_BOM_AND_MO') && $this->fk_product > 0) { - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($this->fk_product); - if ($tmpproduct->hasFatherOrChild(1) > 0) { - $this->error = 'ErrorAVirtualProductCantBeUsedIntoABomOrMo'; - $this->errors[] = $this->error; - return -1; - } - } - @@ -317,9 +250,0 @@ - - if ($this->fk_bom > 0) { - // If there is a nown BOM, we force the type of MO to the type of BOM - include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; - $tmpbom = new BOM($this->db); - $tmpbom->fetch($this->fk_bom); - - $this->mrptype = $tmpbom->bomtype; - } @@ -335 +260 @@ - $result = $this->createProduction($user, $notrigger); // Insert lines from BOM + $result = $this->updateProduction($user, $notrigger); @@ -360,56 +285,42 @@ - $error = 0; - - dol_syslog(__METHOD__, LOG_DEBUG); - - $object = new self($this->db); - - $this->db->begin(); - - // Load source object - $result = $object->fetchCommon($fromid); - if ($result > 0 && !empty($object->table_element_line)) { - $object->fetchLines(); - } - - // get lines so they will be clone - //foreach($this->lines as $line) - // $line->fetch_optionals(); - - // Reset some properties - unset($object->id); - unset($object->fk_user_creat); - unset($object->import_key); - - // We make $object->lines empty to sort it without produced and consumed lines - $TLines = $object->lines; - $object->lines = array(); - - // Remove produced and consumed lines - foreach ($TLines as $key => $line) { - if (in_array($line->role, array('consumed', 'produced'))) { - unset($object->lines[$key]); - } else { - $object->lines[] = $line; - } - } - - - // Clear fields - $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default']; - $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default']; - $object->status = self::STATUS_DRAFT; - // ... - // Clear extrafields that are unique - if (is_array($object->array_options) && count($object->array_options) > 0) { - $extrafields->fetch_name_optionals_label($this->table_element); - foreach ($object->array_options as $key => $option) { - $shortkey = preg_replace('/options_/', '', $key); - if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) { - //var_dump($key); - //var_dump($clonedObj->array_options[$key]); exit; - unset($object->array_options[$key]); - } - } - } - - // Create clone + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + $object = new self($this->db); + + $this->db->begin(); + + // Load source object + $result = $object->fetchCommon($fromid); + if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines(); + + // get lines so they will be clone + //foreach($this->lines as $line) + // $line->fetch_optionals(); + + // Reset some properties + unset($object->id); + unset($object->fk_user_creat); + unset($object->import_key); + + // Clear fields + $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default']; + $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default']; + $object->status = self::STATUS_DRAFT; + // ... + // Clear extrafields that are unique + if (is_array($object->array_options) && count($object->array_options) > 0) + { + $extrafields->fetch_name_optionals_label($this->table_element); + foreach ($object->array_options as $key => $option) + { + $shortkey = preg_replace('/options_/', '', $key); + if (!empty($extrafields->attributes[$this->element]['unique'][$shortkey])) + { + //var_dump($key); var_dump($clonedObj->array_options[$key]); exit; + unset($object->array_options[$key]); + } + } + } + + // Create clone @@ -417,33 +328,36 @@ - $result = $object->createCommon($user); - if ($result < 0) { - $error++; - $this->error = $object->error; - $this->errors = $object->errors; - } - - if (!$error) { - // copy internal contacts - if ($this->copy_linked_contact($object, 'internal') < 0) { - $error++; - } - } - - if (!$error) { - // copy external contacts if same company - if (property_exists($this, 'socid') && $this->socid == $object->socid) { - if ($this->copy_linked_contact($object, 'external') < 0) { - $error++; - } - } - } - - unset($object->context['createfromclone']); - - // End - if (!$error) { - $this->db->commit(); - return $object; - } else { - $this->db->rollback(); - return -1; - } + $result = $object->createCommon($user); + if ($result < 0) { + $error++; + $this->error = $object->error; + $this->errors = $object->errors; + } + + if (!$error) + { + // copy internal contacts + if ($this->copy_linked_contact($object, 'internal') < 0) + { + $error++; + } + } + + if (!$error) + { + // copy external contacts if same company + if (property_exists($this, 'socid') && $this->socid == $object->socid) + { + if ($this->copy_linked_contact($object, 'external') < 0) + $error++; + } + } + + unset($object->context['createfromclone']); + + // End + if (!$error) { + $this->db->commit(); + return $object; + } else { + $this->db->rollback(); + return -1; + } @@ -457 +371 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -462,6 +376 @@ - if ($result > 0 && !empty($this->table_element_line)) { - $this->fetchLines(); - } - - $this->socid = $this->fk_soc; - + if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines(); @@ -474 +383 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -507,5 +416,2 @@ - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { - $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')'; - } else { - $sql .= ' WHERE 1 = 1'; - } + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; + else $sql .= ' WHERE 1 = 1'; @@ -517,4 +423,6 @@ - $sqlwhere[] = $key." = ".((int) $value); - } elseif (strpos($key, 'date') !== false) { - $sqlwhere[] = $key." = '".$this->db->idate($value)."'"; - } elseif ($key == 'customsql') { + $sqlwhere[] = $key.'='.$value; + } + elseif (strpos($key, 'date') !== false) { + $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; + } + elseif ($key == 'customsql') { @@ -522,2 +430,3 @@ - } else { - $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'"; + } + else { + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; @@ -528 +437 @@ - $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')'; + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; @@ -535 +444 @@ - $sql .= $this->db->plimit($limit, $offset); + $sql .= ' '.$this->db->plimit($limit, $offset); @@ -541,3 +450,4 @@ - $i = 0; - while ($i < min($limit, $num)) { - $obj = $this->db->fetch_object($resql); + $i = 0; + while ($i < min($limit, $num)) + { + $obj = $this->db->fetch_object($resql); @@ -579,5 +489,2 @@ - if ($lineid > 0) { - $sql .= ' AND t.fk_mrp_production = '.((int) $lineid); - } else { - $sql .= 'AND t.fk_mo = '.((int) $this->id); - } + if ($lineid > 0) $sql .= ' AND t.fk_mrp_production = '.$lineid; + else $sql .= 'AND t.fk_mo = '.$this->id; @@ -601,2 +508 @@ - 'fk_stock_movement' => $obj->fk_stock_movement, - 'fk_unit' => $obj->fk_unit + 'fk_stock_movement' => $obj->fk_stock_movement @@ -627 +533 @@ - $sql .= " WHERE sm.origintype = 'mo' and sm.fk_origin = ".((int) $this->id); + $sql .= " WHERE sm.origintype = 'mo' and sm.fk_origin = ".$this->id; @@ -655 +561 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -658,0 +565,2 @@ + global $langs; + @@ -668 +575,0 @@ - // Update the lines (the qty) to consume or to produce @@ -674,0 +582 @@ + setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); @@ -677 +585,3 @@ - } else { + } + else { + setEventMessages($this->error, $this->errors, 'errors'); @@ -683 +592,0 @@ - @@ -689,3 +598,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function createProduction(User $user, $notrigger = true) + * @return int <0 if KO, >0 if OK + */ + public function updateProduction(User $user, $notrigger = true) @@ -694 +602,0 @@ - $role = ""; @@ -696,0 +605 @@ + $this->error = 'BadStatus'; @@ -703,2 +612,5 @@ - if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.((int) $this->id); + if (!$error) + { + // TODO Check that production has not started. If yes, we stop here. + + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'mrp_production WHERE fk_mo = '.$this->id; @@ -712,0 +625 @@ + $moline->role = 'toproduce'; @@ -714,23 +626,0 @@ - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($this->fk_product); - $moline->fk_unit = $tmpproduct->fk_unit; - - if ($this->fk_bom > 0) { // If a BOM is defined, we know what to produce. - include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; - $bom = new BOM($this->db); - $bom->fetch($this->fk_bom); - if ($bom->bomtype == 1) { - $role = 'toproduce'; - $moline->role = 'toconsume'; - } else { - $role = 'toconsume'; - $moline->role = 'toproduce'; - } - } else { - if ($this->mrptype == 1) { - $moline->role = 'toconsume'; - } else { - $moline->role = 'toproduce'; - } - } @@ -747 +637,5 @@ - if ($bom->id > 0) { + include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; + $bom = new Bom($this->db); + $bom->fetch($this->fk_bom); + if ($bom->id > 0) + { @@ -750 +644,2 @@ - foreach ($bom->lines as $line) { + foreach ($bom->lines as $line) + { @@ -754,5 +648,0 @@ - $moline->origin_id = $line->id; - $moline->origin_type = 'bomline'; - if (!empty($line->fk_unit)) { - $moline->fk_unit = $line->fk_unit; - } @@ -762 +652 @@ - $moline->qty = price2num(($line->qty / (!empty($bom->qty) ? $bom->qty : 1)) * $this->qty / (!empty($line->efficiency) ? $line->efficiency : 1), 'MS'); // Calculate with Qty to produce and more presition + $moline->qty = price2num(($line->qty / $bom->qty) * $this->qty / $line->efficiency, 'MS'); // Calculate with Qty to produce and more presition @@ -768 +658,2 @@ - } else { + } + else { @@ -770 +661 @@ - $moline->role = $role; + $moline->role = 'toconsume'; @@ -774,3 +664,0 @@ - if (!empty($line->fk_default_workstation)) { - $moline->fk_default_workstation = $line->fk_default_workstation; - } @@ -802,52 +689,0 @@ - /** - * Update quantities in lines to consume and/or lines to produce. - * - * @param User $user User that modifies - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function updateProduction(User $user, $notrigger = true) - { - $error = 0; - - if ($this->status != self::STATUS_DRAFT) { - return 1; - } - - $this->db->begin(); - - $oldQty = $this->oldQty; - $newQty = $this->qty; - if ($newQty != $oldQty && !empty($this->oldQty)) { - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "mrp_production WHERE fk_mo = " . (int) $this->id; - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $moLine = new MoLine($this->db); - $res = $moLine->fetch($obj->rowid); - if (!$res) { - $error++; - } - - if ($moLine->role == 'toconsume' || $moLine->role == 'toproduce') { - if (empty($moLine->qty_frozen)) { - $qty = $newQty * $moLine->qty / $oldQty; - $moLine->qty = price2num($qty, 'MS'); - $res = $moLine->update($user); - if (!$res) { - $error++; - } - } - } - } - } - } - if (!$error) { - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } - @@ -858,31 +694,8 @@ - * @param User $user User that deletes - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @param bool $also_cancel_consumed_and_produced_lines true if the consumed and produced lines will be deleted (and stocks incremented/decremented back) (false by default) - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete(User $user, $notrigger = false, $also_cancel_consumed_and_produced_lines = false) - { - $error = 0; - $this->db->begin(); - - if ($also_cancel_consumed_and_produced_lines) { - $result = $this->cancelConsumedAndProducedLines($user, 0, false, $notrigger); - if ($result < 0) { - $error++; - } - } - - if (!$error) { - $result = $this->deleteCommon($user, $notrigger); - if ($result < 0) { - $error++; - } - } - - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } + * @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); @@ -901,4 +714,2 @@ - global $langs; - $langs->loadLangs(array('stocks', 'mrp')); - - if ($this->status < 0) { + if ($this->status < 0) + { @@ -908,87 +719,2 @@ - $productstatic = new Product($this->db); - $fk_movement = GETPOST('fk_movement', 'int'); - $arrayoflines = $this->fetchLinesLinked('consumed', $idline); // Get lines consumed under the one to delete - - $result = 0; - - $this->db->begin(); - - if (!empty($arrayoflines)) { - // If there is child lines - $stockmove = new MouvementStock($this->db); - $stockmove->setOrigin($this->element, $this->id); - - if (!empty($fk_movement)) { - // The fk_movement was not recorded so we try to guess the product and quantity to restore. - $moline = new MoLine($this->db); - $TArrayMoLine = $moline->fetchAll('', '', 1, 0, array('customsql' => 'fk_stock_movement = '.(int) $fk_movement)); - $moline = array_shift($TArrayMoLine); - - $movement = new MouvementStock($this->db); - $movement->fetch($fk_movement); - $productstatic->fetch($movement->product_id); - $qtytoprocess = $movement->qty; - - // Reverse stock movement - $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref); - $codemovementCancel = $langs->trans("StockIncrease"); - - if (($qtytoprocess >= 0)) { - $idstockmove = $stockmove->reception($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, '', '', $movement->batch, dol_now(), 0, $codemovementCancel); - } else { - $idstockmove = $stockmove->livraison($user, $movement->product_id, $movement->warehouse_id, $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $movement->batch, 0, $codemovementCancel); - } - if ($idstockmove < 0) { - $this->error++; - setEventMessages($stockmove->error, $stockmove->errors, 'errors'); - } else { - $result = $moline->delete($user, $notrigger); - } - } else { - // Loop on each child lines - foreach ($arrayoflines as $key => $arrayofline) { - $lineDetails = $arrayoflines[$key]; - $productstatic->fetch($lineDetails['fk_product']); - $qtytoprocess = $lineDetails['qty']; - - // Reverse stock movement - $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref); - $codemovementCancel = $langs->trans("StockIncrease"); - - - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel); - } else { - $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel); - } - if ($idstockmove < 0) { - $this->error++; - setEventMessages($stockmove->error, $stockmove->errors, 'errors'); - } else { - $moline = new MoLine($this->db); - $moline->fetch($lineDetails['rowid']); - - $resdel = $moline->delete($user, $notrigger); - if ($resdel < 0) { - $this->error++; - setEventMessages($moline->error, $moline->errors, 'errors'); - } - } - } - - if (empty($this->error)) { - $result = $this->deleteLineCommon($user, $idline, $notrigger); - } - } - } else { - // No child lines - $result = $this->deleteLineCommon($user, $idline, $notrigger); - } - - if (!empty($this->error) || $result <= 0) { - $this->db->rollback(); - } else { - $this->db->commit(); - } - - return $result; + + return $this->deleteLineCommon($user, $idline, $notrigger); @@ -1010 +736,2 @@ - if (getDolGlobalString('MRP_MO_ADDON')) { + if (!empty($conf->global->MRP_MO_ADDON)) + { @@ -1013 +740 @@ - $file = getDolGlobalString('MRP_MO_ADDON') . ".php"; + $file = $conf->global->MRP_MO_ADDON.".php"; @@ -1018 +745,2 @@ - foreach ($dirmodels as $reldir) { + foreach ($dirmodels as $reldir) + { @@ -1025 +753,2 @@ - if ($mybool === false) { + if ($mybool === false) + { @@ -1033 +762,2 @@ - if ($numref != "") { + if ($numref != "") + { @@ -1035 +765,3 @@ - } else { + } + else + { @@ -1040 +772,3 @@ - } else { + } + else + { @@ -1051 +785 @@ - * @return int Return integer <=0 if OK, 0=Nothing done, >0 if KO + * @return int <=0 if OK, 0=Nothing done, >0 if KO @@ -1062 +796,2 @@ - if ($this->status == self::STATUS_VALIDATED) { + if ($this->status == self::STATUS_VALIDATED) + { @@ -1067,2 +802,2 @@ - /*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)))) + /*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)))) @@ -1080 +815,2 @@ - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life + { @@ -1083 +819,3 @@ - } else { + } + else + { @@ -1094 +832 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -1098 +836,2 @@ - if (!$resql) { + if (!$resql) + { @@ -1104 +843,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -1107,3 +847 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -1113 +851,2 @@ - if (!$error) { + if (!$error) + { @@ -1117 +856,2 @@ - if (preg_match('/^[\(]?PROV/i', $this->ref)) { + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { @@ -1122,11 +862 @@ - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'mrp/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'mrp/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } + if (!$resql) { $error++; $this->error = $this->db->lasterror(); } @@ -1139 +869,2 @@ - if (!$error && file_exists($dirsource)) { + if (!$error && file_exists($dirsource)) + { @@ -1142 +873,2 @@ - if (@rename($dirsource, $dirdest)) { + if (@rename($dirsource, $dirdest)) + { @@ -1146 +878,2 @@ - foreach ($listoffiles as $fileentry) { + foreach ($listoffiles as $fileentry) + { @@ -1159 +892,2 @@ - if (!$error) { + if (!$error) + { @@ -1164 +898,2 @@ - if (!$error) { + if (!$error) + { @@ -1167 +902,3 @@ - } else { + } + else + { @@ -1178 +915 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -1183 +920,2 @@ - if ($this->status <= self::STATUS_DRAFT) { + if ($this->status <= self::STATUS_DRAFT) + { @@ -1187,2 +925,2 @@ - /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate)))) + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) @@ -1200,6 +938,5 @@ - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @param bool $also_cancel_consumed_and_produced_lines true if the consumed and produced lines will be deleted (and stocks incremented/decremented back) (false by default) - * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK - */ - public function cancel($user, $notrigger = 0, $also_cancel_consumed_and_produced_lines = false) + * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers + * @return int <0 if KO, 0=Nothing done, >0 if OK + */ + public function cancel($user, $notrigger = 0) @@ -1208 +945,2 @@ - if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) { + if ($this->status != self::STATUS_VALIDATED && $this->status != self::STATUS_INPROGRESS) + { @@ -1212,2 +950,2 @@ - /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate)))) + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) @@ -1219,24 +957 @@ - $error = 0; - $this->db->begin(); - - if ($also_cancel_consumed_and_produced_lines) { - $result = $this->cancelConsumedAndProducedLines($user, 0, true, $notrigger); - if ($result < 0) { - $error++; - } - } - - if (!$error) { - $result = $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL'); - if ($result < 0) { - $error++; - } - } - - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } + return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MRP_MO_CANCEL'); @@ -1250 +965 @@ - * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK + * @return int <0 if KO, 0=Nothing done, >0 if OK @@ -1255 +970,2 @@ - if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) { + if ($this->status != self::STATUS_PRODUCED && $this->status != self::STATUS_CANCELED) + { @@ -1259,2 +975,2 @@ - /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->mymodule->mymodule_advance->validate)))) + /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->write)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->mymodule->mymodule_advance->validate)))) @@ -1269,217 +985,48 @@ - /** - * Cancel consumed and produced lines (movement stocks) - * - * @param User $user Object user that modify - * @param bool $mode Type line supported (0 by default) (0: consumed and produced lines; 1: consumed lines; 2: produced lines) - * @param bool $also_delete_lines true if the consumed/produced lines is deleted (false by default) - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK - */ - public function cancelConsumedAndProducedLines($user, $mode = 0, $also_delete_lines = false, $notrigger = 0) - { - global $langs; - - if (!isModEnabled('stock')) { - return 1; - } - - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; - require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; - $error = 0; - $langs->load('stocks'); - - $this->db->begin(); - - // Cancel consumed lines - if (empty($mode) || $mode == 1) { - $arrayoflines = $this->fetchLinesLinked('consumed'); - if (!empty($arrayoflines)) { - foreach ($arrayoflines as $key => $lineDetails) { - $productstatic = new Product($this->db); - $productstatic->fetch($lineDetails['fk_product']); - $qtytoprocess = $lineDetails['qty']; - - // Reverse stock movement - $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref); - $codemovementCancel = $langs->trans("StockIncrease"); - - $stockmove = new MouvementStock($this->db); - $stockmove->setOrigin($this->element, $this->id); - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel); - } else { - $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel); - } - if ($idstockmove < 0) { - $this->error = $stockmove->error; - $this->errors = $stockmove->errors; - $error++; - break; - } - - if ($also_delete_lines) { - $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger); - if ($result < 0) { - $error++; - break; - } - } - } - } - } - - // Cancel produced lines - if (empty($mode) || $mode == 2) { - $arrayoflines = $this->fetchLinesLinked('produced'); - if (!empty($arrayoflines)) { - foreach ($arrayoflines as $key => $lineDetails) { - $productstatic = new Product($this->db); - $productstatic->fetch($lineDetails['fk_product']); - $qtytoprocess = $lineDetails['qty']; - - // Reverse stock movement - $labelmovementCancel = $langs->trans("CancelProductionForRef", $productstatic->ref); - $codemovementCancel = $langs->trans("StockDecrease"); - - $stockmove = new MouvementStock($this->db); - $stockmove->setOrigin($this->element, $this->id); - if ($qtytoprocess >= 0) { - $idstockmove = $stockmove->livraison($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, dol_now(), '', '', $lineDetails['batch'], 0, $codemovementCancel); - } else { - $idstockmove = $stockmove->reception($user, $lineDetails['fk_product'], $lineDetails['fk_warehouse'], $qtytoprocess, 0, $labelmovementCancel, '', '', $lineDetails['batch'], dol_now(), 0, $codemovementCancel); - } - if ($idstockmove < 0) { - $this->error = $stockmove->error; - $this->errors = $stockmove->errors; - $error++; - break; - } - - if ($also_delete_lines) { - $result = $this->deleteLineCommon($user, $lineDetails['rowid'], $notrigger); - if ($result < 0) { - $error++; - break; - } - } - } - } - } - - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } - } - - /** - * getTooltipContentArray - * - * @param array $params ex option, infologin - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $conf, $langs; - - $langs->loadLangs(['mrp', 'products']); - $nofetch = isset($params['nofetch']) ? true : false; - - $datas = []; - - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("ManufacturingOrder").''; - if (isset($this->status)) { - $datas['picto'] .= ' '.$this->getLibStatut(5); - } - $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; - if (isset($this->label)) { - $datas['label'] = '
'.$langs->trans('Label').': '.$this->label; - } - if (isset($this->mrptype)) { - $datas['type'] = '
'.$langs->trans('Type').': '.$this->fields['mrptype']['arrayofkeyval'][$this->mrptype]; - } - if (isset($this->qty)) { - $datas['qty'] = '
'.$langs->trans('QtyToProduce').': '.$this->qty; - } - if (!$nofetch && isset($this->fk_product)) { - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; - $product = new Product($this->db); - $product->fetch($this->fk_product); - $datas['product'] = '
'.$langs->trans('Product').': '.$product->getNomUrl(1, '', 0, -1, 1); - } - if (!$nofetch && isset($this->fk_warehouse)) { - require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; - $warehouse = new Entrepot($this->db); - $warehouse->fetch($this->fk_warehouse); - $datas['warehouse'] = '
'.$langs->trans('WarehouseForProduction').': '.$warehouse->getNomUrl(1, '', 0, 1); - } - - return $datas; - } - - /** - * Return a link to the object card (with optionaly the picto) - * - * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) - * @param string $option On what the link point to ('nolink', '', 'production', ...) - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string String with URL - */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) - { - global $conf, $langs, $action, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } - - $result = ''; - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'option' => $option, - 'nofetch' => 1, - ]; - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); - } - - $url = DOL_URL_ROOT.'/mrp/mo_card.php?id='.$this->id; - if ($option == 'production') { - $url = DOL_URL_ROOT.'/mrp/mo_production.php?id='.$this->id; - } - - if ($option != 'nolink') { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - } - - $linkclose = ''; - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $label = $langs->trans("ShowMo"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } + /** + * Return a link to the object card (with optionaly the picto) + * + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param string $option On what the link point to ('nolink', '', 'production', ...) + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL + */ + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + { + global $conf, $langs, $hookmanager; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + + $label = ''.$langs->trans("MO").''; + $label .= '
'; + $label .= ''.$langs->trans('Ref').': '.$this->ref; + if (isset($this->status)) { + $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); + } + + $url = dol_buildpath('/mrp/mo_card.php', 1).'?id='.$this->id; + if ($option == 'production') $url = dol_buildpath('/mrp/mo_production.php', 1).'?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkclose = ''; + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("ShowMo"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -1492,6 +1039,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; @@ -1500,0 +1044 @@ + global $action, $hookmanager; @@ -1502 +1046 @@ - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); @@ -1504,5 +1048,2 @@ - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; @@ -1511 +1052 @@ - } + } @@ -1524 +1065 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1535 +1076,2 @@ - if (empty($this->labelStatus)) { + if (empty($this->labelStatus)) + { @@ -1538,11 +1080,11 @@ - $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('ValidatedToProduce'); - $this->labelStatus[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress'); - $this->labelStatus[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced'); - $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled'); - - $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated'); - $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->transnoentitiesnoconv('InProgress'); - $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->transnoentitiesnoconv('StatusMOProduced'); - $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled'); + $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft'); + $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' ('.$langs->trans("ToProduce").')'; + $this->labelStatus[self::STATUS_INPROGRESS] = $langs->trans('InProgress'); + $this->labelStatus[self::STATUS_PRODUCED] = $langs->trans('StatusMOProduced'); + $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled'); + + $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft'); + $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated'); + $this->labelStatusShort[self::STATUS_INPROGRESS] = $langs->trans('InProgress'); + $this->labelStatusShort[self::STATUS_PRODUCED] = $langs->trans('StatusMOProduced'); + $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled'); @@ -1552,12 +1094,4 @@ - if ($status == self::STATUS_VALIDATED) { - $statusType = 'status1'; - } - if ($status == self::STATUS_INPROGRESS) { - $statusType = 'status4'; - } - if ($status == self::STATUS_PRODUCED) { - $statusType = 'status6'; - } - if ($status == self::STATUS_CANCELED) { - $statusType = 'status9'; - } + if ($status == self::STATUS_VALIDATED) $statusType = 'status1'; + if ($status == self::STATUS_INPROGRESS) $statusType = 'status4'; + if ($status == self::STATUS_PRODUCED) $statusType = 'status6'; + if ($status == self::STATUS_CANCELED) $statusType = 'status9'; @@ -1579 +1113 @@ - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql .= ' WHERE t.rowid = '.$id; @@ -1581,2 +1115,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -1584 +1119,0 @@ - @@ -1586,3 +1121,21 @@ - - $this->user_creation_id = $obj->fk_user_creat; - $this->user_modification_id = $obj->fk_user_modif; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db); + $cluser->fetch($obj->fk_user_cloture); + $this->user_cloture = $cluser; + } + @@ -1590 +1143,2 @@ - $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem); + $this->date_modification = $this->db->jdate($obj->datem); + $this->date_validation = $this->db->jdate($obj->datev); @@ -1594 +1148,3 @@ - } else { + } + else + { @@ -1608,2 +1163,0 @@ - - $this->lines = array(); @@ -1615,23 +1169,20 @@ - * @param string $rolefilter string lines role filter - * @return array|int array of lines if OK, <0 if KO - */ - public function getLinesArray($rolefilter = '') - { - $this->lines = array(); - - $objectline = new MoLine($this->db); - - $TFilters = array('customsql'=>'fk_mo = '.((int) $this->id)); - if (!empty($rolefilter)) { - $TFilters['role'] = $rolefilter; - } - $result = $objectline->fetchAll('ASC', 'position', 0, 0, $TFilters); - - if (is_numeric($result)) { - $this->error = $objectline->error; - $this->errors = $objectline->errors; - return $result; - } else { - $this->lines = $result; - return $this->lines; - } + * @return array|int array of lines if OK, <0 if KO + */ + public function getLinesArray() + { + $this->lines = array(); + + $objectline = new MoLine($this->db); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_mo = '.$this->id)); + + if (is_numeric($result)) + { + $this->error = $this->error; + $this->errors = $this->errors; + return $result; + } + else + { + $this->lines = $result; + return $this->lines; + } @@ -1661,4 +1212,4 @@ - if ($this->model_pdf) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('MRP_MO_ADDON_PDF')) { - $modele = getDolGlobalString('MRP_MO_ADDON_PDF'); + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->MO_ADDON_PDF)) { + $modele = $conf->global->MO_ADDON_PDF; @@ -1670,3 +1221 @@ - if (empty($modele)) { - return 1; // Remove this once a pdf_standard.php exists. - } + if (empty($modele)) return 1; // Remove this once a pdf_standard.php exists. @@ -1719,12 +1268 @@ - global $langs, $hookmanager, $conf, $form, $action; - - $langs->load('stocks'); - $text_stock_options = $langs->trans("RealStockDesc").'
'; - $text_stock_options .= $langs->trans("RealStockWillAutomaticallyWhen").'
'; - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ? '- '.$langs->trans("DeStockOnShipment").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_VALIDATE_ORDER') ? '- '.$langs->trans("DeStockOnValidateOrder").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_BILL') ? '- '.$langs->trans("DeStockOnBill").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_BILL') ? '- '.$langs->trans("ReStockOnBill").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ? '- '.$langs->trans("ReStockOnValidateOrder").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ? '- '.$langs->trans("ReStockOnDispatchOrder").'
' : ''); - $text_stock_options .= (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE') ? '- '.$langs->trans("StockOnReception").'
' : ''); + global $langs, $hookmanager, $conf, $form; @@ -1733,20 +1271,2 @@ - // Product or sub-bom - print ''.$langs->trans('Ref'); - if (getDolGlobalString('BOM_SUB_BOM')) { - print '   '.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'  '; - print ''.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").' '; - } - print ''; - // Qty - print ''.$langs->trans('Qty'); - if ($this->bom->bomtype == 0) { - print ' ('.$langs->trans("ForAQuantityOf", $this->bom->qty).')'; - } else { - print ' ('.$langs->trans("ForAQuantityToConsumeOf", $this->bom->qty).')'; - } - // Unit - print ''.$langs->trans('Unit'); - - print ''; - print ''.$form->textwithpicto($langs->trans("PhysicalStock"), $text_stock_options, 1).''; - print ''.$form->textwithpicto($langs->trans("VirtualStock"), $langs->trans("VirtualStockDesc")).''; + print ''.$langs->trans('Ref').''; + print ''.$langs->trans('Qty').' ('.$langs->trans("ForAQuantityOf", $this->bom->qty).')'; @@ -1755 +1275 @@ - print ''.$langs->trans('MoChildGenerate').''; + //print ''.$langs->trans('Efficiency').''; @@ -1757 +1277 @@ - //print ''; + print ''; @@ -1761,7 +1281,11 @@ - if (!empty($this->lines)) { - foreach ($this->lines as $line) { - $reshook = 0; - if (is_object($hookmanager)) { - $parameters = array('line'=>$line, 'i'=>$i, 'restrictlist'=>$restrictlist, 'selectedLines'=> $selectedLines); - if (!empty($line->fk_parent_line)) { - $parameters['fk_parent_line'] = $line->fk_parent_line; + if (!empty($this->lines)) + { + foreach ($this->lines as $line) + { + /*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 = ''; + $result = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks @@ -1769,3 +1293,3 @@ - $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - } - if (empty($reshook)) { + } + else + {*/ @@ -1773 +1297 @@ - } + //} @@ -1787 +1311 @@ - * @param MoLine $line Line + * @param CommonObjectLine $line Line @@ -1796 +1320 @@ - $productstatic = new Product($this->db); + global $langs, $conf; @@ -1801 +1325,3 @@ - if (!empty($line->fk_product) && $line->fk_product > 0) { + if (!empty($line->fk_product)) + { + $productstatic = new Product($this->db); @@ -1803 +1328,0 @@ - $productstatic->load_virtual_stock(); @@ -1806,2 +1331,4 @@ - } else { - // If origin MO line is not a product, but another MO + } + else + { + // If origin MRP line is not a product, but another MRP @@ -1816,3 +1342,0 @@ - $this->tpl['stock'] = $productstatic->stock_reel; - $this->tpl['seuil_stock_alerte'] = $productstatic->seuil_stock_alerte; - $this->tpl['virtual_stock'] = $productstatic->stock_theorique; @@ -1820 +1343,0 @@ - $this->tpl['fk_unit'] = $line->fk_unit; @@ -1825,183 +1348,2 @@ - global $conf; // used into template - $res = include DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php'; - } - - /** - * Function used to replace a thirdparty id with another one. - * - * @param DoliDB $db Database handler - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @return bool - */ - public static function replaceThirdparty($db, $origin_id, $dest_id) - { - $tables = array('mrp_mo'); - - return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); - } - - - /** - * Function used to return childs of Mo - * - * @return Mo[]|int array if OK, -1 if KO - */ - public function getMoChilds() - { - $TMoChilds = array(); - $error = 0; - - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_mo as mo_child"; - $sql.= " WHERE fk_parent_line IN "; - $sql.= " (SELECT rowid FROM ".MAIN_DB_PREFIX."mrp_production as line_parent"; - $sql.= " WHERE fk_mo=".((int) $this->id).")"; - - $resql = $this->db->query($sql); - - if ($resql) { - if ($this->db->num_rows($resql) > 0) { - while ($obj = $this->db->fetch_object($resql)) { - $MoChild = new Mo($this->db); - $res = $MoChild->fetch($obj->rowid); - if ($res > 0) { - $TMoChilds[$MoChild->id] = $MoChild; - } else { - $error++; - } - } - } - } else { - $error++; - } - - if ($error) { - return -1; - } else { - return $TMoChilds; - } - } - - /** - * Function used to return all child MOs recursively - * - * @param int $depth Depth for recursing loop count - * @return Mo[]|int[] array of MOs if OK, -1 if KO - */ - public function getAllMoChilds($depth = 0) - { - if ($depth > 1000) { - return -1; - } - - $TMoChilds = array(); - $error = 0; - - $childMoList = $this->getMoChilds(); - - if ($childMoList == -1) { - return -1; - } - - foreach ($childMoList as $childMo) { - $TMoChilds[$childMo->id] = $childMo; - } - - foreach ($childMoList as $childMo) { - $childMoChildren = $childMo->getAllMoChilds($depth + 1); - - if ($childMoChildren == -1) { - $error++; - } else { - foreach ($childMoChildren as $child) { - $TMoChilds[$child->id] = $child; - } - } - } - - if ($error) { - return -1; - } else { - return $TMoChilds; - } - } - - - - /** - * Function used to return childs of Mo - * - * @return Mo|int MO object if OK, -1 if KO, 0 if not exist - */ - public function getMoParent() - { - $MoParent = new Mo($this->db); - $error = 0; - - $sql = "SELECT lineparent.fk_mo as id_moparent FROM ".MAIN_DB_PREFIX."mrp_mo as mo"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."mrp_production lineparent ON mo.fk_parent_line = lineparent.rowid"; - $sql.= " WHERE mo.rowid = ".((int) $this->id); - - $resql = $this->db->query($sql); - - if ($resql) { - if ($this->db->num_rows($resql) > 0) { - $obj = $this->db->fetch_object($resql); - $res = $MoParent->fetch($obj->id_moparent); - if ($res < 0) { - $error++; - } - } else { - return 0; - } - } else { - $error++; - } - - if ($error) { - return -1; - } else { - return $MoParent; - } - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - //$return .= ''; // Can be image - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (!empty($arraydata['bom'])) { - $return .= '
'.$arraydata['bom']->getNomUrl(1).''; - } - if (!empty($arraydata['product'])) { - $return .= '
'.$arraydata['product']->getNomUrl(1).''; - } - if (property_exists($this, 'qty')) { - $return .= '
'.$langs->trans('Quantity').' : '.$this->qty.''; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; + $tpl = DOL_DOCUMENT_ROOT.'/mrp/tpl/originproductline.tpl.php'; + $res = include $tpl; @@ -2034 +1376 @@ - public $isextrafieldmanaged = 1; + public $isextrafieldmanaged = 0; @@ -2039,2 +1380,0 @@ - 'origin_id' =>array('type'=>'integer', 'label'=>'Origin', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>17), - 'origin_type' =>array('type'=>'varchar(10)', 'label'=>'Origin type', 'enabled'=>1, 'visible'=>-1, 'notnull'=>0, 'position'=>18), @@ -2045,2 +1385,2 @@ - 'qty_frozen' => array('type'=>'smallint', 'label'=>'QuantityFrozen', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'notnull' => 1, 'position'=>105, 'css'=>'maxwidth50imp', 'help'=>'QuantityConsumedInvariable'), - 'disable_stock_change' => array('type'=>'smallint', 'label'=>'DisableStockChange', 'enabled'=>1, 'visible'=>1, 'default'=>0, 'notnull' => 1, 'position'=>108, 'css'=>'maxwidth50imp', 'help'=>'DisableStockChangeHelp'), + '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'), @@ -2051 +1391 @@ - 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>160), + 'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>160), @@ -2056,2 +1395,0 @@ - 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>185), - 'fk_unit' =>array('type'=>'int', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>186) @@ -2062,2 +1399,0 @@ - public $origin_id; - public $origin_type; @@ -2070 +1405,0 @@ - public $efficiency; @@ -2080,7 +1414,0 @@ - public $fk_parent_line; - public $fk_unit; - - /** - * @var int Service Workstation - */ - public $fk_default_workstation; @@ -2099,6 +1427,2 @@ - if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) { - $this->fields['rowid']['visible'] = 0; - } - if (!isModEnabled('multicompany') && isset($this->fields['entity'])) { - $this->fields['entity']['enabled'] = 0; - } + 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; @@ -2107,2 +1431,4 @@ - foreach ($this->fields as $key => $val) { - if (isset($val['enabled']) && empty($val['enabled'])) { + foreach ($this->fields as $key => $val) + { + if (isset($val['enabled']) && empty($val['enabled'])) + { @@ -2114,4 +1440,8 @@ - if (is_object($langs)) { - foreach ($this->fields as $key => $val) { - if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { - foreach ($val['arrayofkeyval'] as $key2 => $val2) { + if (is_object($langs)) + { + foreach ($this->fields as $key => $val) + { + if (is_array($val['arrayofkeyval'])) + { + foreach ($val['arrayofkeyval'] as $key2 => $val2) + { @@ -2130 +1460 @@ - * @return int Return integer <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK @@ -2147 +1477 @@ - * @return int Return integer <0 if KO, 0 if not found, >0 if OK + * @return int <0 if KO, 0 if not found, >0 if OK @@ -2151,0 +1482 @@ + if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines(); @@ -2177,5 +1508,2 @@ - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) { - $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')'; - } else { - $sql .= ' WHERE 1 = 1'; - } + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')'; + else $sql .= ' WHERE 1 = 1'; @@ -2187,4 +1515,6 @@ - $sqlwhere[] = $key." = ".((int) $value); - } elseif (strpos($key, 'date') !== false) { - $sqlwhere[] = $key." = '".$this->db->idate($value)."'"; - } elseif ($key == 'customsql') { + $sqlwhere[] = $key.'='.$value; + } + elseif (strpos($key, 'date') !== false) { + $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; + } + elseif ($key == 'customsql') { @@ -2192,2 +1522,3 @@ - } else { - $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'"; + } + else { + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; @@ -2198 +1529 @@ - $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')'; + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')'; @@ -2205 +1536 @@ - $sql .= $this->db->plimit($limit, $offset); + $sql .= ' '.$this->db->plimit($limit, $offset); @@ -2212 +1543,2 @@ - while ($i < ($limit ? min($limit, $num) : $num)) { + while ($i < min($limit, $num)) + { @@ -2238 +1570 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2250 +1582 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK