From 752c35d6d1d9a3f59a39e0bf066c214b0910203c Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Thu, 4 Oct 2018 17:32:50 +0200 Subject: [PATCH] addline presque fini --- .../class/fournisseur.commande.class.php | 4 +- .../fournisseur.commande.dispatch.class.php | 19 +- htdocs/reception/card.php | 644 +++++------------- .../reception/class/expeditionbatch.class.php | 223 ------ htdocs/reception/class/reception.class.php | 191 +----- 5 files changed, 236 insertions(+), 845 deletions(-) delete mode 100644 htdocs/reception/class/expeditionbatch.class.php diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index aa596170cbf..c7edd289ae6 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2955,12 +2955,12 @@ class CommandeFournisseur extends CommonOrder $sql.= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; $sql.= ' WHERE'; if ($filtre_statut >= 0) $sql.= ' cfd.fk_reception = e.rowid AND'; - $sql.= ' cfd.commandefourndet = cd.rowid'; + $sql.= ' cfd.fk_commandefourndet = cd.rowid'; $sql.= ' AND cd.fk_commande =' .$this->id; if ($this->fk_product > 0) $sql.= ' AND cd.fk_product = '.$this->fk_product; if ($filtre_statut >= 0) $sql.=' AND e.fk_statut >= '.$filtre_statut; $sql.= ' GROUP BY cd.rowid, cd.fk_product'; - //print $sql; + dol_syslog(get_class($this)."::loadReceptions", LOG_DEBUG); $result = $this->db->query($sql); diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index 7fd56f81aac..ecc920d86de 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -104,7 +104,7 @@ class CommandeFournisseurDispatch extends CommonObject if (isset($this->comment)) $this->comment=trim($this->comment); if (isset($this->status)) $this->status=trim($this->status); if (isset($this->batch)) $this->batch=trim($this->batch); - + if(empty($this->datec)) $this->datec == dol_now(); // Check parameters @@ -166,6 +166,23 @@ class CommandeFournisseurDispatch extends CommonObject //// End call triggers } } + + // Actions on extra fields (by external module or standard code) + // TODO le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('commandefournisseurdispatchdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } // Commit or rollback if ($error) diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 4be1dc7f822..1db0156560e 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -45,7 +45,10 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; +if (! empty($conf->fournisseur->enabled)){ + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; +} if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -212,201 +215,154 @@ if (empty($reshook)) // Create reception if ($action == 'add' && $user->rights->reception->creer) { - $error=0; - $predef=''; + $error = 0; + $predef = ''; - $db->begin(); + $db->begin(); - $object->note = GETPOST('note','alpha'); - $object->origin = $origin; - $object->origin_id = $origin_id; - $object->fk_project = GETPOST('projectid','int'); - $object->weight = GETPOST('weight','int')==''?"NULL":GETPOST('weight','int'); - $object->sizeH = GETPOST('sizeH','int')==''?"NULL":GETPOST('sizeH','int'); - $object->sizeW = GETPOST('sizeW','int')==''?"NULL":GETPOST('sizeW','int'); - $object->sizeS = GETPOST('sizeS','int')==''?"NULL":GETPOST('sizeS','int'); - $object->size_units = GETPOST('size_units','int'); - $object->weight_units = GETPOST('weight_units','int'); + $object->note = GETPOST('note', 'alpha'); + $object->origin = $origin; + $object->origin_id = $origin_id; + $object->fk_project = GETPOST('projectid', 'int'); + $object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int'); + $object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int'); + $object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int'); + $object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int'); + $object->size_units = GETPOST('size_units', 'int'); + $object->weight_units = GETPOST('weight_units', 'int'); - $date_delivery = dol_mktime(GETPOST('date_deliveryhour','int'), GETPOST('date_deliverymin','int'), 0, GETPOST('date_deliverymonth','int'), GETPOST('date_deliveryday','int'), GETPOST('date_deliveryyear','int')); + $date_delivery = dol_mktime(GETPOST('date_deliveryhour', 'int'), GETPOST('date_deliverymin', 'int'), 0, GETPOST('date_deliverymonth', 'int'), GETPOST('date_deliveryday', 'int'), GETPOST('date_deliveryyear', 'int')); - // On va boucler sur chaque ligne du document d'origine pour completer objet reception - // avec info diverses + qte a livrer - $classname = ucfirst($object->origin); - $objectsrc = new $classname($db); - $objectsrc->fetch($object->origin_id); + // On va boucler sur chaque ligne du document d'origine pour completer objet reception + // avec info diverses + qte a livrer - $object->socid = $objectsrc->socid; - $object->ref_customer = GETPOST('ref_customer','alpha'); - $object->model_pdf = GETPOST('model'); - $object->date_delivery = $date_delivery; // Date delivery planed - $object->fk_delivery_address = $objectsrc->fk_delivery_address; - $object->reception_method_id = GETPOST('reception_method_id','int'); - $object->tracking_number = GETPOST('tracking_number','alpha'); - $object->ref_int = GETPOST('ref_int','alpha'); - $object->note_private = GETPOST('note_private','none'); - $object->note_public = GETPOST('note_public','none'); - $object->fk_incoterms = GETPOST('incoterm_id', 'int'); - $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + if ($object->origin == "supplierorder") + $classname = 'CommandeFournisseur'; + else + $classname = ucfirst($object->origin); + $objectsrc = new $classname($db); + $objectsrc->fetch($object->origin_id); - $batch_line = array(); + + + $object->socid = $objectsrc->socid; + $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); + $object->model_pdf = GETPOST('model'); + $object->date_delivery = $date_delivery; // Date delivery planed + $object->fk_delivery_address = $objectsrc->fk_delivery_address; + $object->reception_method_id = GETPOST('reception_method_id', 'int'); + $object->tracking_number = GETPOST('tracking_number', 'alpha'); + $object->ref_int = GETPOST('ref_int', 'alpha'); + $object->note_private = GETPOST('note_private', 'none'); + $object->note_public = GETPOST('note_public', 'none'); + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); + + $batch_line = array(); $stockLine = array(); - $array_options=array(); + $array_options = array(); - $num=count($objectsrc->lines); - $totalqty=0; + $totalqty = 0; - for ($i = 0; $i < $num; $i++) - { - $idl="idl".$i; + $num = 0; + foreach ($_POST as $key => $value) + { + // without batch module enabled - $sub_qty=array(); - $subtotalqty=0; - - $j=0; - $batch="batchl".$i."_0"; - $stockLocation="ent1".$i."_0"; - $qty = "qtyl".$i; - - if ($objectsrc->lines[$i]->product_tobatch) // If product need a batch number + if (strpos($key, 'qtyasked') !== false) { - if (isset($_POST[$batch])) - { - //reception line with batch-enable product - $qty .= '_'.$j; - while (isset($_POST[$batch])) - { - // save line of detail into sub_qty - $sub_qty[$j]['q']=GETPOST($qty,'int'); // the qty we want to move for this stock record - $sub_qty[$j]['id_batch']=GETPOST($batch,'int'); // the id into llx_product_batch of stock record to move - $subtotalqty+=$sub_qty[$j]['q']; - - //var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']); - - $j++; - $batch="batchl".$i."_".$j; - $qty = "qtyl".$i.'_'.$j; - } - - $batch_line[$i]['detail']=$sub_qty; // array of details - $batch_line[$i]['qty']=$subtotalqty; - $batch_line[$i]['ix_l']=GETPOST($idl,'int'); - - $totalqty+=$subtotalqty; - } - else - { - // No detail were provided for lots - if (! empty($_POST[$qty])) - { - // We try to set an amount - // Case we dont use the list of available qty for each warehouse/lot - // GUI does not allow this yet - setEventMessage('StockIsRequiredToChooseWhichLotToUse', 'errors'); - } - } + $num++; } - else if (isset($_POST[$stockLocation])) - { - //reception line from multiple stock locations - $qty .= '_'.$j; - while (isset($_POST[$stockLocation])) - { - // save sub line of warehouse - $stockLine[$i][$j]['qty']=GETPOST($qty,'int'); - $stockLine[$i][$j]['warehouse_id']=GETPOST($stockLocation,'int'); - $stockLine[$i][$j]['ix_l']=GETPOST($idl,'int'); + } - $totalqty+=GETPOST($qty,'int'); + for ($i = 1; $i <= $num; $i++) + { + $idl = "idl".$i; - $j++; - $stockLocation="ent1".$i."_".$j; - $qty = "qtyl".$i.'_'.$j; - } - } - else - { - //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit; + $sub_qty = array(); + $subtotalqty = 0; + + $j = 0; + $batch = "batchl".$i."_0"; + $stockLocation = "ent1".$i."_0"; + $qty = "qtyl".$i; + + + + //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit; //reception line for product with no batch management and no multiple stock location - if (GETPOST($qty,'int') > 0) $totalqty+=GETPOST($qty,'int'); - } + if (GETPOST($qty, 'int') > 0) + $totalqty += GETPOST($qty, 'int'); + // Extrafields $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i); + $array_options[$i] = $extrafieldsline->getOptionalsFromPost($extralabelsline, $i); + // Unset extrafield - if (is_array($extralabelsline)) { + if (is_array($extralabelsline)) + { // Get extra fields - foreach ($extralabelsline as $key => $value) { - unset($_POST["options_" . $key]); + foreach ($extralabelsline as $key => $value) + { + unset($_POST["options_".$key]); } } + } - } - //var_dump($batch_line[2]); + - if ($totalqty > 0) // There is at least one thing to ship - { - //var_dump($_POST);exit; - for ($i = 0; $i < $num; $i++) - { - $qty = "qtyl".$i; - if (! isset($batch_line[$i])) + if ($totalqty > 0) // There is at least one thing to ship + { + //var_dump($_POST);exit; + for ($i = 1; $i <= $num; $i++) + { + $lineToTest = ''; + foreach($objectsrc->lines as $linesrc){ + if($linesrc->id == GETPOST($idl, 'int'))$lineToTest=$linesrc; + } + $qty = "qtyl".$i; + $comment = "comment".$i; + $eatby = "dlc".$i; + $sellby = "dluo".$i; + $batch = "batch".$i; + + + + $timeFormat = '%d/%m/%Y'; + + if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS)) { - // not batch mode - if (isset($stockLine[$i])) + $ent = "entl".$i; + + $idl = "idl".$i; + + $entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int'); + if ($entrepot_id < 0) + $entrepot_id = ''; + if (!($linesrc->fk_product > 0)) + $entrepot_id = 0; + $eatby = GETPOST($eatby, 'alpha'); + $sellby = GETPOST($sellby, 'alpha'); + $eatbydate = str_replace('/','-',$eatby); + $sellbydate = str_replace('/','-',$sellby); + var_dump($entrepot_id); + + + $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate),strtotime($sellbydate), GETPOST($batch, 'alpha')); + if ($ret < 0) { - //reception from multiple stock locations - $nbstockline = count($stockLine[$i]); - for($j = 0; $j < $nbstockline; $j++) - { - if ($stockLine[$i][$j]['qty']>0) - { - $ret=$object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]); - if ($ret < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - } - } - else - { - if (GETPOST($qty,'int') > 0 || (GETPOST($qty,'int') == 0 && $conf->global->RECEPTION_GETS_ALL_ORDER_PRODUCTS)) - { - $ent = "entl".$i; - $idl = "idl".$i; - $entrepot_id = is_numeric(GETPOST($ent,'int'))?GETPOST($ent,'int'):GETPOST('entrepot_id','int'); - if ($entrepot_id < 0) $entrepot_id=''; - if (! ($objectsrc->lines[$i]->fk_product > 0)) $entrepot_id = 0; - - $ret=$object->addline($entrepot_id, GETPOST($idl,'int'), GETPOST($qty,'int'), $array_options[$i]); - if ($ret < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } + setEventMessages($object->error, $object->errors, 'errors'); + $error++; } } - else - { - // batch mode - if ($batch_line[$i]['qty']>0) - { - $ret=$object->addline_batch($batch_line[$i],$array_options[$i]); - if ($ret < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - } - } + } + var_dump($object->lines);exit; // TODO CHECK LINES + // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; if (! $error) @@ -1115,6 +1071,7 @@ if ($action == 'create') // Document model include_once DOL_DOCUMENT_ROOT . '/core/modules/reception/modules_reception.php'; $liste = ModelePdfReception::liste_modeles($db); + if (count($liste) > 1) { print "".$langs->trans("DefaultModel").""; @@ -1136,7 +1093,7 @@ if ($action == 'create') // without batch module enabled if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) { - + $numAsked ++; // $numline=$reg[2] + 1; // line of product $numline = $numAsked; @@ -1147,13 +1104,13 @@ if ($action == 'create') $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2]; $dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int')); - $numAsked ++; + } // with batch module enabled if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { - +$numAsked ++; // eat-by date dispatch // $numline=$reg[2] + 1; // line of product $numline = $numAsked; @@ -1166,10 +1123,9 @@ if ($action == 'create') $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']); $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; $dispatchLines[$numAsked]=array('prod' => GETPOST($prod, 'int'), 'qty' =>GETPOST($qty), 'ent' =>GETPOST($ent, 'int'), 'pu' =>GETPOST($pu), 'comment' =>GETPOST('comment'),'fk_commandefourndet' => GETPOST($fk_commandefourndet, 'int'),'DLC'=> $dDLC,'DLUO'=> $dDLUO,'lot'=> GETPOST($lot, 'alpha')); - $numAsked ++; + } } - $numAsked --; print '