addline presque fini
This commit is contained in:
parent
5fe767d7bd
commit
752c35d6d1
@ -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);
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 "<tr><td>".$langs->trans("DefaultModel")."</td>";
|
||||
@ -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 '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
@ -1217,32 +1173,32 @@ if ($action == 'create')
|
||||
print '</td>';
|
||||
if (! empty($conf->stock->enabled))
|
||||
{
|
||||
if (empty($conf->productbatch->enabled))
|
||||
{
|
||||
print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="left">'.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' ('.$langs->trans("Stock").')</td>';
|
||||
}
|
||||
|
||||
print '<td align="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
|
||||
|
||||
}
|
||||
if (!empty($conf->productbatch->enabled))
|
||||
{
|
||||
print '<td align="left">'.$langs->trans("batch_number").'</td>';
|
||||
print '<td align="left">'.$langs->trans("EatByDate").'</td>';
|
||||
print '<td align="left">'.$langs->trans("SellByDate").'</td>';
|
||||
}
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
$var=true;
|
||||
$indiceAsked = 0;
|
||||
while ($indiceAsked < $numAsked)
|
||||
$indiceAsked =1;
|
||||
while ($indiceAsked <= $numAsked)
|
||||
{
|
||||
$product = new Product($db);
|
||||
foreach($object->lines as $supplierLine){
|
||||
if($dispatchLines[$indiceAsked]['prod'] == $supplierLine->id){
|
||||
if($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id){
|
||||
$line = $supplierLine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Show product and description
|
||||
$type=$line->product_type?$line->product_type:$line->fk_product_type;
|
||||
// Try to enhance type detection using date_start and date_end for free lines where type
|
||||
@ -1252,7 +1208,9 @@ if ($action == 'create')
|
||||
|
||||
print '<!-- line '.$line->rowid.' for product -->'."\n";
|
||||
print '<tr class="oddeven">'."\n";
|
||||
|
||||
print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value=\''.$line->id.'\' />';
|
||||
print '<input type="hidden" name="comment'.$indiceAsked.'" value=\''.GETPOST('comment').'\' />';
|
||||
|
||||
// Product label
|
||||
if ($line->fk_product > 0) // If predefined product
|
||||
{
|
||||
@ -1262,12 +1220,13 @@ if ($action == 'create')
|
||||
|
||||
print '<td>';
|
||||
print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
||||
|
||||
|
||||
// Show product and description
|
||||
$product_static->type=$line->fk_product_type;
|
||||
$product_static->id=$line->fk_product;
|
||||
$product_static->ref=$line->ref;
|
||||
$product_static->status_batch=$line->product_tobatch;
|
||||
|
||||
$text=$product_static->getNomUrl(1);
|
||||
$text.= ' - '.(! empty($line->label)?$line->label:$line->product_label);
|
||||
$description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->desc));
|
||||
@ -1301,15 +1260,17 @@ if ($action == 'create')
|
||||
print_date_range($db->jdate($line->date_start),$db->jdate($line->date_end));
|
||||
print "</td>\n";
|
||||
}
|
||||
|
||||
|
||||
// Qty
|
||||
print '<td align="center">'.$dispatchLines[$indiceAsked]['qty'];
|
||||
print '<td align="center">'.$line->qty;
|
||||
print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$dispatchLines[$indiceAsked]['qty'].'">';
|
||||
print '</td>';
|
||||
$qtyProdCom=$line->qty;
|
||||
|
||||
// Qty already received
|
||||
print '<td align="center">';
|
||||
|
||||
|
||||
$quantityDelivered = $object->receptions[$line->id];
|
||||
print $quantityDelivered;
|
||||
print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
|
||||
@ -1324,19 +1285,18 @@ if ($action == 'create')
|
||||
{
|
||||
$quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
|
||||
}
|
||||
$warehouse_id = GETPOST('entrepot_id','int');
|
||||
var_dump($dispatchLines);exit;
|
||||
//@TODO TODO
|
||||
$warehouse_id = $dispatchLines[$indiceAsked]['ent'];
|
||||
|
||||
$warehouseObject = null;
|
||||
if ($warehouse_id > 0 || ! ($line->fk_product > 0) || empty($conf->stock->enabled)) // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
|
||||
{
|
||||
print '<!-- Case warehouse already known or product not a predefined product -->';
|
||||
//ship from preselected location
|
||||
$stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number
|
||||
$deliverableQty=min($quantityToBeDelivered, $stock);
|
||||
if ($deliverableQty < 0) $deliverableQty = 0;
|
||||
if (empty($conf->productbatch->enabled) || ! $product->hasbatch())
|
||||
{
|
||||
|
||||
$stock = + $product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
|
||||
$deliverableQty=$dispatchLines[$indiceAsked]['qty'];
|
||||
|
||||
|
||||
|
||||
// Quantity to send
|
||||
print '<td align="center">';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
|
||||
@ -1347,7 +1307,7 @@ if ($action == 'create')
|
||||
}
|
||||
else print $langs->trans("NA");
|
||||
print '</td>';
|
||||
|
||||
|
||||
// Stock
|
||||
if (! empty($conf->stock->enabled))
|
||||
{
|
||||
@ -1378,9 +1338,25 @@ if ($action == 'create')
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
|
||||
if(!empty($conf->productbatch->enabled) ){
|
||||
if( !empty($product->status_batch)){
|
||||
print '<td><input name="batch'.$indiceAsked.'" value="'.$dispatchLines[$indiceAsked]['lot'].'"></td>';
|
||||
print '<td>';
|
||||
print $form->select_date($dispatchLines[$indiceAsked]['DLC'],'dlc' . $indiceAsked, '', '', 1, "");
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $form->select_date($dispatchLines[$indiceAsked]['DLUO'],'dluo' . $indiceAsked, '', '', 1, "");
|
||||
print '</td>';
|
||||
}else {
|
||||
print '<td colspan="3"></td>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
print "</tr>\n";
|
||||
|
||||
|
||||
// Show subproducts of product
|
||||
if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
|
||||
{
|
||||
@ -1403,281 +1379,23 @@ if ($action == 'create')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Product need lot
|
||||
print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
|
||||
|
||||
$staticwarehouse=new Entrepot($db);
|
||||
if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id);
|
||||
|
||||
$subj=0;
|
||||
// Define nb of lines suggested for this order line
|
||||
$nbofsuggested=0;
|
||||
if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))
|
||||
{
|
||||
foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)
|
||||
{
|
||||
$nbofsuggested++;
|
||||
}
|
||||
}
|
||||
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
|
||||
if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))
|
||||
{
|
||||
foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)
|
||||
{
|
||||
//var_dump($dbatch);
|
||||
$batchStock = + $dbatch->qty; // To get a numeric
|
||||
$deliverableQty = min($quantityToBeDelivered,$batchStock);
|
||||
print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'>';
|
||||
print '<td colspan="3" ></td><td align="center">';
|
||||
print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
|
||||
print '</td>';
|
||||
|
||||
print '<!-- Show details of lot -->';
|
||||
print '<td align="left">';
|
||||
|
||||
print $staticwarehouse->getNomUrl(0).' / ';
|
||||
|
||||
print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
|
||||
|
||||
$detail='';
|
||||
$detail.= $langs->trans("Batch").': '.$dbatch->batch;
|
||||
$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
|
||||
$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
|
||||
$detail.= ' - '.$langs->trans("Qty").': '.$dbatch->dluo_qty;
|
||||
$detail.= '<br>';
|
||||
print $detail;
|
||||
|
||||
$quantityToBeDelivered -= $deliverableQty;
|
||||
if ($quantityToBeDelivered < 0)
|
||||
{
|
||||
$quantityToBeDelivered = 0;
|
||||
}
|
||||
$subj++;
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<!-- Case there is no details of lot at all -->';
|
||||
print '<tr class="oddeven"><td colspan="3"></td><td align="center">';
|
||||
print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';
|
||||
print '</td>';
|
||||
|
||||
print '<td align="left">';
|
||||
print img_warning().' '.$langs->trans("NoProductToReceiveFoundIntoStock", $staticwarehouse->libelle);
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// ship from multiple locations
|
||||
if (empty($conf->productbatch->enabled) || ! $product->hasbatch())
|
||||
{
|
||||
print '<!-- Case warehouse not already known and product does not need lot -->';
|
||||
print '<td></td><td></td></tr>'."\n"; // end line and start a new one for each warehouse
|
||||
|
||||
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
|
||||
$subj=0;
|
||||
// Define nb of lines suggested for this order line
|
||||
$nbofsuggested=0;
|
||||
foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
|
||||
{
|
||||
if ($stock_warehouse->real > 0)
|
||||
{
|
||||
$nbofsuggested++;
|
||||
}
|
||||
}
|
||||
$tmpwarehouseObject=new Entrepot($db);
|
||||
foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) // $stock_warehouse is product_stock
|
||||
{
|
||||
$tmpwarehouseObject->fetch($warehouse_id);
|
||||
if ($stock_warehouse->real > 0)
|
||||
{
|
||||
$stock = + $stock_warehouse->real; // Convert it to number
|
||||
$deliverableQty = min($quantityToBeDelivered,$stock);
|
||||
$deliverableQty = max(0, $deliverableQty);
|
||||
// Quantity to send
|
||||
print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'>';
|
||||
print '<td colspan="3" ></td><td align="center"><!-- qty to ship (no lot management for product line indiceAsked='.$indiceAsked.') -->';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
|
||||
{
|
||||
print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
|
||||
print '<input name="ent1'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$warehouse_id.'">';
|
||||
}
|
||||
else print $langs->trans("NA");
|
||||
print '</td>';
|
||||
|
||||
// Stock
|
||||
if (! empty($conf->stock->enabled))
|
||||
{
|
||||
print '<td align="left">';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
|
||||
{
|
||||
print $tmpwarehouseObject->getNomUrl(0).' ';
|
||||
|
||||
print '<!-- Show details of stock -->';
|
||||
print '('.$stock.')';
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("Service");
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
$quantityToBeDelivered -= $deliverableQty;
|
||||
if ($quantityToBeDelivered < 0)
|
||||
{
|
||||
$quantityToBeDelivered = 0;
|
||||
}
|
||||
$subj++;
|
||||
print "</tr>\n";
|
||||
}
|
||||
}
|
||||
// Show subproducts of product (not recommanded)
|
||||
if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)
|
||||
{
|
||||
$product->get_sousproduits_arbo();
|
||||
$prods_arbo = $product->get_arbo_each_prod($qtyProdCom);
|
||||
if (count($prods_arbo) > 0)
|
||||
{
|
||||
foreach($prods_arbo as $key => $value)
|
||||
{
|
||||
//print $value[0];
|
||||
$img='';
|
||||
if ($value['stock'] < $value['stock_alert'])
|
||||
{
|
||||
$img=img_warning($langs->trans("StockTooLow"));
|
||||
}
|
||||
print '<tr class"oddeven"><td>';
|
||||
print " ->
|
||||
<a href=\"".DOL_URL_ROOT."/product/card.php?id=".$value['id']."\">".$value['fullpath']."
|
||||
</a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td> </td><td> </td>
|
||||
<td align=\"center\">".$value['stock']." ".$img."</td>";
|
||||
print "</tr>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<!-- Case warehouse not already known and product need lot -->';
|
||||
print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial
|
||||
|
||||
$subj=0;
|
||||
print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
|
||||
|
||||
$tmpwarehouseObject=new Entrepot($db);
|
||||
$productlotObject=new Productlot($db);
|
||||
// Define nb of lines suggested for this order line
|
||||
$nbofsuggested=0;
|
||||
foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
|
||||
{
|
||||
if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
|
||||
foreach ($stock_warehouse->detail_batch as $dbatch)
|
||||
{
|
||||
$nbofsuggested++;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)
|
||||
{
|
||||
$tmpwarehouseObject->fetch($warehouse_id);
|
||||
if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {
|
||||
foreach ($stock_warehouse->detail_batch as $dbatch)
|
||||
{
|
||||
//var_dump($dbatch);
|
||||
$batchStock = + $dbatch->qty; // To get a numeric
|
||||
$deliverableQty = min($quantityToBeDelivered,$batchStock);
|
||||
if ($deliverableQty < 0) $deliverableQty = 0;
|
||||
print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested)?$bc[$var]:'').'><td colspan="3"></td><td align="center">';
|
||||
print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';
|
||||
print '</td>';
|
||||
|
||||
print '<td align="left">';
|
||||
|
||||
print $tmpwarehouseObject->getNomUrl(0).' / ';
|
||||
|
||||
print '<!-- Show details of lot -->';
|
||||
print '<input name="batchl'.$indiceAsked.'_'.$subj.'" type="hidden" value="'.$dbatch->id.'">';
|
||||
|
||||
//print $line->fk_product.' - '.$dbatch->batch;
|
||||
print $langs->trans("Batch").': ';
|
||||
$result = $productlotObject->fetch(0, $line->fk_product, $dbatch->batch);
|
||||
if ($result > 0) print $productlotObject->getNomUrl(1);
|
||||
else print 'TableLotIncompleteRunRepair';
|
||||
print ' ('.$dbatch->qty.')';
|
||||
$quantityToBeDelivered -= $deliverableQty;
|
||||
if ($quantityToBeDelivered < 0)
|
||||
{
|
||||
$quantityToBeDelivered = 0;
|
||||
}
|
||||
//dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock);
|
||||
$subj++;
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ($subj == 0) // Line not shown yet, we show it
|
||||
{
|
||||
print '<!-- line not shown yet, we show it -->';
|
||||
print '<tr class="oddeven"><td colspan="3" ></td><td align="center">';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
|
||||
{
|
||||
$disabled='';
|
||||
if (! empty($conf->productbatch->enabled) && $product->hasbatch())
|
||||
{
|
||||
$disabled='disabled="disabled"';
|
||||
}
|
||||
print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled?' '.$disabled:'').'> ';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NA");
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
print '<td align="left">';
|
||||
if ($line->product_type == Product::TYPE_PRODUCT || ! empty($conf->global->STOCK_SUPPORTS_SERVICES))
|
||||
{
|
||||
$warehouse_selected_id = GETPOST('entrepot_id','int');
|
||||
if ($warehouse_selected_id > 0)
|
||||
{
|
||||
$warehouseObject=new Entrepot($db);
|
||||
$warehouseObject->fetch($warehouse_selected_id);
|
||||
print img_warning().' '.$langs->trans("NoProductToReceiveFoundIntoStock", $warehouseObject->libelle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($line->fk_product) print img_warning().' '.$langs->trans("StockTooLow");
|
||||
else print '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("Service");
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Display lines extrafields
|
||||
if (is_array($extralabelslines) && count($extralabelslines)>0)
|
||||
{
|
||||
$colspan=5;
|
||||
if($conf->productbatch->enabled)$colspan+=3;
|
||||
$orderLineExtrafields = new Extrafields($db);
|
||||
$orderLineExtrafieldLabels = $orderLineExtrafields->fetch_name_optionals_label($object->table_element_line);
|
||||
$srcLine = new OrderLine($db);
|
||||
$srcLine = new CommandeFournisseurLigne($db);
|
||||
$srcLine->fetch_optionals($line->id,$orderLineExtrafieldLabels); // fetch extrafields also available in orderline
|
||||
$line = new ReceptionLigne($db);
|
||||
$line = new CommandeFournisseurDispatch($db);
|
||||
$line->fetch_optionals($object->id,$extralabelslines);
|
||||
$line->array_options = array_merge($line->array_options, $srcLine->array_options);
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
@ -1,223 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007-2015 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file expedition/class/expeditionbatch.class.php
|
||||
* \ingroup productbatch
|
||||
* \brief This file implements CRUD method for managing shipment batch lines
|
||||
* with batch record
|
||||
*/
|
||||
|
||||
/**
|
||||
* CRUD class for batch number management within shipment
|
||||
*/
|
||||
class ExpeditionLineBatch extends CommonObject
|
||||
{
|
||||
var $element='expeditionlignebatch'; //!< Id that identify managed objects
|
||||
private static $_table_element='expeditiondet_batch'; //!< Name of table without prefix where object is stored
|
||||
|
||||
var $sellby;
|
||||
var $eatby;
|
||||
var $batch;
|
||||
var $dluo_qty;
|
||||
var $entrepot_id;
|
||||
var $fk_origin_stock;
|
||||
var $fk_expeditiondet;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DoliDb $db Database handler
|
||||
*/
|
||||
function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill object based on a product-warehouse-batch's record
|
||||
*
|
||||
* @param int $id_stockdluo Rowid in product_batch table
|
||||
* @return int -1 if KO, 1 if OK
|
||||
*/
|
||||
function fetchFromStock($id_stockdluo)
|
||||
{
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.sellby,";
|
||||
$sql.= " t.eatby,";
|
||||
$sql.= " t.batch,";
|
||||
$sql.= " e.fk_entrepot";
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_batch as t inner join ";
|
||||
$sql.= MAIN_DB_PREFIX."product_stock as e on t.fk_product_stock=e.rowid ";
|
||||
$sql.= " WHERE t.rowid = ".(int) $id_stockdluo;
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->num_rows($resql))
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->sellby = $this->db->jdate($obj->sellby);
|
||||
$this->eatby = $this->db->jdate($obj->eatby);
|
||||
$this->batch = $obj->batch;
|
||||
$this->entrepot_id= $obj->fk_entrepot;
|
||||
$this->fk_origin_stock=(int) $id_stockdluo;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error="Error ".$this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an expeditiondet_batch DB record link to an expedtiondet record
|
||||
*
|
||||
* @param int $id_line_expdet rowid of expedtiondet record
|
||||
* @return int <0 if KO, Id of record (>0) if OK
|
||||
*/
|
||||
function create($id_line_expdet)
|
||||
{
|
||||
$error = 0;
|
||||
|
||||
$id_line_expdet = (int) $id_line_expdet;
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." (";
|
||||
$sql.= "fk_expeditiondet";
|
||||
$sql.= ", sellby";
|
||||
$sql.= ", eatby";
|
||||
$sql.= ", batch";
|
||||
$sql.= ", qty";
|
||||
$sql.= ", fk_origin_stock";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $id_line_expdet.",";
|
||||
$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':("'".$this->db->idate($this->sellby))."'").",";
|
||||
$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':("'".$this->db->idate($this->eatby))."'").",";
|
||||
$sql.= " ".(! isset($this->batch)?'NULL':("'".$this->db->escape($this->batch)."'")).",";
|
||||
$sql.= " ".(! isset($this->dluo_qty)?'NULL':$this->dluo_qty).",";
|
||||
$sql.= " ".(! isset($this->fk_origin_stock)?'NULL':$this->fk_origin_stock);
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element);
|
||||
$this->fk_expeditiondet=$id_line_expdet;
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($this->errors as $errmsg)
|
||||
{
|
||||
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
|
||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
||||
}
|
||||
$this->db->rollback();
|
||||
return -1*$error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete batch record attach to a shipment
|
||||
*
|
||||
* @param DoliDB $db Database object
|
||||
* @param int $id_expedition rowid of shipment
|
||||
* @return int -1 if KO, 1 if OK
|
||||
*/
|
||||
static function deletefromexp($db,$id_expedition)
|
||||
{
|
||||
$id_expedition = (int) $id_expedition;
|
||||
|
||||
$sql="DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element;
|
||||
$sql.=" WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")";
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
if ($db->query($sql))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all batch number details link to a shipment line
|
||||
*
|
||||
* @param DoliDB $db Database object
|
||||
* @param int $id_line_expdet id of shipment line
|
||||
* @return variant -1 if KO, array of ExpeditionLineBatch if OK
|
||||
*/
|
||||
static function fetchAll($db,$id_line_expdet)
|
||||
{
|
||||
$sql="SELECT rowid,";
|
||||
$sql.= "fk_expeditiondet";
|
||||
$sql.= ", sellby";
|
||||
$sql.= ", eatby";
|
||||
$sql.= ", batch";
|
||||
$sql.= ", qty";
|
||||
$sql.= ", fk_origin_stock";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.self::$_table_element;
|
||||
$sql.= " WHERE fk_expeditiondet=".(int) $id_line_expdet;
|
||||
|
||||
dol_syslog(__METHOD__ ."", LOG_DEBUG);
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num=$db->num_rows($resql);
|
||||
$i=0;
|
||||
$ret = array();
|
||||
while ($i<$num)
|
||||
{
|
||||
$tmp=new self($db);
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
|
||||
$tmp->sellby = $db->jdate($obj->sellby);
|
||||
$tmp->eatby = $db->jdate($obj->eatby);
|
||||
$tmp->batch = $obj->batch;
|
||||
$tmp->id = $obj->rowid;
|
||||
$tmp->fk_origin_stock = $obj->fk_origin_stock;
|
||||
$tmp->fk_expeditiondet = $obj->fk_expeditiondet;
|
||||
$tmp->dluo_qty = $obj->qty;
|
||||
|
||||
$ret[]=$tmp;
|
||||
$i++;
|
||||
}
|
||||
$db->free($resql);
|
||||
return $ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -35,7 +35,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
|
||||
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
|
||||
if (! empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionbatch.class.php';
|
||||
|
||||
|
||||
/**
|
||||
@ -46,7 +45,7 @@ class Reception extends CommonObject
|
||||
public $element="reception";
|
||||
public $fk_element="fk_reception";
|
||||
public $table_element="reception";
|
||||
public $table_element_line="receptiondet";
|
||||
public $table_element_line="commande_fournisseur_dispatch";
|
||||
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
|
||||
public $picto = 'reception';
|
||||
|
||||
@ -267,19 +266,15 @@ class Reception extends CommonObject
|
||||
for ($i = 0; $i < $num; $i++)
|
||||
{
|
||||
if (! isset($this->lines[$i]->detail_batch))
|
||||
{ // no batch management
|
||||
if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->array_options) > 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // with batch management
|
||||
if (! $this->create_line_batch($this->lines[$i],$this->lines[$i]->array_options) > 0)
|
||||
{
|
||||
$this->lines[$i]->fk_reception = $this->id;
|
||||
|
||||
if (! $this->lines[$i]->create() > 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (! $error && $this->id && $this->origin_id)
|
||||
@ -358,62 +353,6 @@ class Reception extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a reception line
|
||||
*
|
||||
* @param int $entrepot_id Id of warehouse
|
||||
* @param int $origin_line_id Id of source line
|
||||
* @param int $qty Quantity
|
||||
* @param array $array_options extrafields array
|
||||
* @return int <0 if KO, line_id if OK
|
||||
*/
|
||||
function create_line($entrepot_id, $origin_line_id, $qty,$array_options=0)
|
||||
{
|
||||
global $conf;
|
||||
$error = 0;
|
||||
$line_id = 0;
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."receptiondet (";
|
||||
$sql.= "fk_reception";
|
||||
$sql.= ", fk_entrepot";
|
||||
$sql.= ", fk_origin_line";
|
||||
$sql.= ", qty";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $this->id;
|
||||
$sql.= ", ".($entrepot_id?$entrepot_id:'null');
|
||||
$sql.= ", ".$origin_line_id;
|
||||
$sql.= ", ".$qty;
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create_line", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."receptiondet");
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
|
||||
{
|
||||
$receptionline = new ReceptionLigne($this->db);
|
||||
$receptionline->array_options=$array_options;
|
||||
$receptionline->id= $this->db->last_insert_id(MAIN_DB_PREFIX.$receptionline->table_element);
|
||||
$result=$receptionline->insertExtraFields();
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error[]=$receptionline->error;
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error) return $line_id;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the detail (eat-by date) of the reception line
|
||||
*
|
||||
@ -854,30 +793,34 @@ class Reception extends CommonObject
|
||||
* If STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS is set, you can add a reception line, with no stock source defined
|
||||
* If STOCK_MUST_BE_ENOUGH_FOR_RECEPTION is not set, you can add a reception line, even if not enough into stock
|
||||
*
|
||||
* @param int $entrepot_id Id of warehouse
|
||||
* @param int $id Id of source line (order line)
|
||||
* @param int $qty Quantity
|
||||
* @param array $array_options extrafields array
|
||||
* @param int $entrepot_id Id of warehouse
|
||||
* @param int $id Id of source line (supplier order line)
|
||||
* @param int $qty Quantity
|
||||
* @param array $array_options extrafields array
|
||||
* @param string $comment Comment for stock movement
|
||||
* @param date $eatby eat-by date
|
||||
* @param date $sellby sell-by date
|
||||
* @param string $batch Lot number
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function addline($entrepot_id, $id, $qty,$array_options=0)
|
||||
function addline($entrepot_id, $id, $qty, $array_options=0, $comment='', $eatby='', $sellby='', $batch='')
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $conf, $langs, $user;
|
||||
|
||||
$num = count($this->lines);
|
||||
$line = new ReceptionLigne($this->db);
|
||||
$line = new CommandeFournisseurDispatch($this->db);
|
||||
|
||||
$line->entrepot_id = $entrepot_id;
|
||||
$line->origin_line_id = $id;
|
||||
$line->fk_entrepot = $entrepot_id;
|
||||
$line->fk_commandefourndet = $id;
|
||||
$line->qty = $qty;
|
||||
|
||||
$orderline = new OrderLine($this->db);
|
||||
$orderline->fetch($id);
|
||||
$supplierorderline = new CommandeFournisseurLigne($this->db);
|
||||
$supplierorderline->fetch($id);
|
||||
|
||||
if (! empty($conf->stock->enabled) && ! empty($orderline->fk_product))
|
||||
if (! empty($conf->stock->enabled) && ! empty($supplierorderline->fk_product))
|
||||
{
|
||||
$fk_product = $orderline->fk_product;
|
||||
|
||||
$fk_product = $supplierorderline->fk_product;
|
||||
|
||||
if (! ($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_RECEPTIONS))
|
||||
{
|
||||
$langs->load("errors");
|
||||
@ -909,87 +852,23 @@ class Reception extends CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
// If product need a batch number, we should not have called this function but addline_batch instead.
|
||||
if (! empty($conf->productbatch->enabled) && ! empty($orderline->fk_product) && ! empty($orderline->product_tobatch))
|
||||
{
|
||||
$this->error='ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH';
|
||||
return -4;
|
||||
}
|
||||
|
||||
// extrafields
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
|
||||
$line->array_options = $array_options;
|
||||
|
||||
$line->fk_product = $fk_product;
|
||||
$line->fk_commande = $supplierorderline->fk_commande ;
|
||||
$line->fk_user = $user->id ;
|
||||
$line->comment = $comment;
|
||||
$line->batch = $batch;
|
||||
$line->eatby = $eatby;
|
||||
$line->sellby = $sellby;
|
||||
$line->status=1;
|
||||
$line->fk_reception=$this->id;
|
||||
|
||||
$this->lines[$num] = $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a reception line with batch record
|
||||
*
|
||||
* @param array $dbatch Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
|
||||
* @param array $array_options extrafields array
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function addline_batch($dbatch,$array_options=0)
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
$num = count($this->lines);
|
||||
if ($dbatch['qty']>0)
|
||||
{
|
||||
$line = new ReceptionLigne($this->db);
|
||||
$tab=array();
|
||||
foreach ($dbatch['detail'] as $key=>$value)
|
||||
{
|
||||
if ($value['q']>0)
|
||||
{
|
||||
// $value['q']=qty to move
|
||||
// $value['id_batch']=id into llx_product_batch of record to move
|
||||
//var_dump($value);
|
||||
|
||||
$linebatch = new ReceptionLineBatch($this->db);
|
||||
$ret=$linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby
|
||||
if ($ret<0)
|
||||
{
|
||||
$this->error=$linebatch->error;
|
||||
return -1;
|
||||
}
|
||||
$linebatch->dluo_qty=$value['q'];
|
||||
$tab[]=$linebatch;
|
||||
|
||||
if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_RECEPTION)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
|
||||
$prod_batch = new Productbatch($this->db);
|
||||
$prod_batch->fetch($value['id_batch']);
|
||||
|
||||
if ($prod_batch->qty < $linebatch->dluo_qty)
|
||||
{
|
||||
$langs->load("errors");
|
||||
$this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnReception', $prod_batch->fk_product);
|
||||
dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($linebatch);
|
||||
}
|
||||
}
|
||||
$line->entrepot_id = $linebatch->entrepot_id;
|
||||
$line->origin_line_id = $dbatch['ix_l'];
|
||||
$line->qty = $dbatch['qty'];
|
||||
$line->detail_batch=$tab;
|
||||
|
||||
// extrafields
|
||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options)>0) // For avoid conflicts if trigger used
|
||||
$line->array_options = $array_options;
|
||||
|
||||
//var_dump($line);
|
||||
$this->lines[$num] = $line;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update database
|
||||
@ -1706,7 +1585,7 @@ class Reception extends CommonObject
|
||||
$this->meths = array();
|
||||
|
||||
$sql = "SELECT em.rowid, em.code, em.libelle";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_reception_mode as em";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em";
|
||||
$sql.= " WHERE em.active = 1";
|
||||
$sql.= " ORDER BY em.libelle ASC";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user