mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 01:28:19 +01:00
NEW entete reception card
This commit is contained in:
@@ -1151,6 +1151,25 @@ abstract class CommonObject
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charge le product d'id $this->fk_product dans this->product
|
||||||
|
*
|
||||||
|
* @return int <0 if KO, >=0 if OK
|
||||||
|
*/
|
||||||
|
function fetch_product()
|
||||||
|
{
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||||
|
|
||||||
|
if (empty($this->fk_product) && ! empty($this->fk_product)) $this->fk_product = $this->fk_product; // For backward compatibility
|
||||||
|
if (empty($this->fk_product)) return 0;
|
||||||
|
|
||||||
|
$product = new Product($this->db);
|
||||||
|
$result = $product->fetch($this->fk_product);
|
||||||
|
|
||||||
|
$this->product = $product;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Charge le user d'id userid dans this->user
|
* Charge le user d'id userid dans this->user
|
||||||
*
|
*
|
||||||
@@ -2464,6 +2483,7 @@ abstract class CommonObject
|
|||||||
// Special case
|
// Special case
|
||||||
if ($origin == 'order') $origin='commande';
|
if ($origin == 'order') $origin='commande';
|
||||||
if ($origin == 'invoice') $origin='facture';
|
if ($origin == 'invoice') $origin='facture';
|
||||||
|
if ($origin == 'supplierorder') $origin='order_supplier';
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
@@ -3097,10 +3117,14 @@ abstract class CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
$weight = $line->weight ? $line->weight : 0;
|
$weight = $line->weight ? $line->weight : 0;
|
||||||
|
($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0;
|
||||||
$volume = $line->volume ? $line->volume : 0;
|
$volume = $line->volume ? $line->volume : 0;
|
||||||
|
($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0;
|
||||||
|
|
||||||
$weight_units=$line->weight_units;
|
$weight_units=$line->weight_units;
|
||||||
|
($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0;
|
||||||
$volume_units=$line->volume_units;
|
$volume_units=$line->volume_units;
|
||||||
|
($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0;
|
||||||
|
|
||||||
$weightUnit=0;
|
$weightUnit=0;
|
||||||
$volumeUnit=0;
|
$volumeUnit=0;
|
||||||
|
|||||||
@@ -391,6 +391,15 @@ class FormFile
|
|||||||
$modellist=ModelePDFExpedition::liste_modeles($this->db);
|
$modellist=ModelePDFExpedition::liste_modeles($this->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($modulepart == 'reception')
|
||||||
|
{
|
||||||
|
if (is_array($genallowed)) $modellist=$genallowed;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
|
||||||
|
$modellist = ModelePdfReception::liste_modeles($this->db);
|
||||||
|
}
|
||||||
|
}
|
||||||
elseif ($modulepart == 'livraison')
|
elseif ($modulepart == 'livraison')
|
||||||
{
|
{
|
||||||
if (is_array($genallowed)) $modellist=$genallowed;
|
if (is_array($genallowed)) $modellist=$genallowed;
|
||||||
@@ -572,6 +581,7 @@ class FormFile
|
|||||||
$res=include_once $file;
|
$res=include_once $file;
|
||||||
}
|
}
|
||||||
$class='Modele'.ucfirst($modulepart);
|
$class='Modele'.ucfirst($modulepart);
|
||||||
|
|
||||||
if (class_exists($class))
|
if (class_exists($class))
|
||||||
{
|
{
|
||||||
$modellist=call_user_func($class.'::liste_modeles',$this->db);
|
$modellist=call_user_func($class.'::liste_modeles',$this->db);
|
||||||
|
|||||||
@@ -34,16 +34,44 @@
|
|||||||
*/
|
*/
|
||||||
function reception_prepare_head(Reception $object)
|
function reception_prepare_head(Reception $object)
|
||||||
{
|
{
|
||||||
global $langs, $conf, $user;
|
global $db, $langs, $conf, $user;
|
||||||
if (! empty($conf->reception->enabled)) $langs->load("receptions");
|
|
||||||
$langs->load("orders");
|
$langs->load("sendings");
|
||||||
|
$langs->load("deliveries");
|
||||||
|
|
||||||
$h = 0;
|
$h = 0;
|
||||||
$head = array();
|
$head = array();
|
||||||
$h = 0;
|
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT."/admin/reception_setup.php";
|
$head[$h][0] = DOL_URL_ROOT."/reception/card.php?id=".$object->id;
|
||||||
$head[$h][1] = $langs->trans("Setup");
|
$head[$h][1] = $langs->trans("ReceptionCard");
|
||||||
|
$head[$h][2] = 'reception';
|
||||||
|
$h++;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
|
||||||
|
{
|
||||||
|
$objectsrc = $object;
|
||||||
|
if ($object->origin == 'commande' && $object->origin_id > 0)
|
||||||
|
{
|
||||||
|
$objectsrc = new Commande($db);
|
||||||
|
$objectsrc->fetch($object->origin_id);
|
||||||
|
}
|
||||||
|
$nbContact = count($objectsrc->liste_contact(-1,'internal')) + count($objectsrc->liste_contact(-1,'external'));
|
||||||
|
$head[$h][0] = DOL_URL_ROOT."/reception/contact.php?id=".$object->id;
|
||||||
|
$head[$h][1] = $langs->trans("ContactsAddresses");
|
||||||
|
if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
|
||||||
|
$head[$h][2] = 'contact';
|
||||||
|
$h++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nbNote = 0;
|
||||||
|
if (!empty($object->note_private)) $nbNote++;
|
||||||
|
if (!empty($object->note_public)) $nbNote++;
|
||||||
|
$head[$h][0] = DOL_URL_ROOT."/reception/note.php?id=".$object->id;
|
||||||
|
$head[$h][1] = $langs->trans("Notes");
|
||||||
|
if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
|
||||||
|
$head[$h][2] = 'note';
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class CommandeFournisseurDispatch extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function create($user, $notrigger=0)
|
function create($user, $notrigger=0)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs, $hookmanager;
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
@@ -104,7 +104,7 @@ class CommandeFournisseurDispatch extends CommonObject
|
|||||||
if (isset($this->comment)) $this->comment=trim($this->comment);
|
if (isset($this->comment)) $this->comment=trim($this->comment);
|
||||||
if (isset($this->status)) $this->status=trim($this->status);
|
if (isset($this->status)) $this->status=trim($this->status);
|
||||||
if (isset($this->batch)) $this->batch=trim($this->batch);
|
if (isset($this->batch)) $this->batch=trim($this->batch);
|
||||||
if(empty($this->datec)) $this->datec == dol_now();
|
if(empty($this->datec)) $this->datec = dol_now();
|
||||||
|
|
||||||
|
|
||||||
// Check parameters
|
// Check parameters
|
||||||
@@ -124,7 +124,8 @@ class CommandeFournisseurDispatch extends CommonObject
|
|||||||
$sql.= "status,";
|
$sql.= "status,";
|
||||||
$sql.= "batch,";
|
$sql.= "batch,";
|
||||||
$sql.= "eatby,";
|
$sql.= "eatby,";
|
||||||
$sql.= "sellby";
|
$sql.= "sellby,";
|
||||||
|
$sql.= "fk_reception";
|
||||||
|
|
||||||
|
|
||||||
$sql.= ") VALUES (";
|
$sql.= ") VALUES (";
|
||||||
@@ -140,7 +141,8 @@ class CommandeFournisseurDispatch extends CommonObject
|
|||||||
$sql.= " ".(! isset($this->status)?'NULL':"'".$this->status."'").",";
|
$sql.= " ".(! isset($this->status)?'NULL':"'".$this->status."'").",";
|
||||||
$sql.= " ".(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").",";
|
$sql.= " ".(! isset($this->batch)?'NULL':"'".$this->db->escape($this->batch)."'").",";
|
||||||
$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby)."'").",";
|
$sql.= " ".(! isset($this->eatby) || dol_strlen($this->eatby)==0?'NULL':"'".$this->db->idate($this->eatby)."'").",";
|
||||||
$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':"'".$this->db->idate($this->sellby)."'")."";
|
$sql.= " ".(! isset($this->sellby) || dol_strlen($this->sellby)==0?'NULL':"'".$this->db->idate($this->sellby)."'").",";
|
||||||
|
$sql.= " ".(! isset($this->fk_reception)?'NULL':"'".$this->fk_reception."'")."";
|
||||||
|
|
||||||
|
|
||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
@@ -228,7 +230,8 @@ class CommandeFournisseurDispatch extends CommonObject
|
|||||||
$sql.= " t.tms,";
|
$sql.= " t.tms,";
|
||||||
$sql.= " t.batch,";
|
$sql.= " t.batch,";
|
||||||
$sql.= " t.eatby,";
|
$sql.= " t.eatby,";
|
||||||
$sql.= " t.sellby";
|
$sql.= " t.sellby,";
|
||||||
|
$sql.= " t.fk_reception";
|
||||||
|
|
||||||
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
|
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
|
||||||
|
|||||||
@@ -794,9 +794,10 @@ if ($id > 0 || ! empty($ref)) {
|
|||||||
if(!empty($conf->reception->enabled) ){
|
if(!empty($conf->reception->enabled) ){
|
||||||
print '<td>';
|
print '<td>';
|
||||||
if (!empty($objp->fk_reception)){
|
if (!empty($objp->fk_reception)){
|
||||||
|
|
||||||
$reception = new Reception($db);
|
$reception = new Reception($db);
|
||||||
$reception->fetch($objp->fk_reception);
|
$reception->fetch($objp->fk_reception);
|
||||||
print $reception->getNomUrl();
|
print $reception->getNomUrl(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</td>";
|
print "</td>";
|
||||||
@@ -866,7 +867,8 @@ if ($id > 0 || ! empty($ref)) {
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
}else if(!empty($conf->reception->enabled)){
|
}else if(!empty($conf->reception->enabled)){
|
||||||
print '<td align="right">';
|
print '<td align="right">';
|
||||||
if(!empty($reception->rowid)){
|
if(!empty($reception->id)){
|
||||||
|
|
||||||
print $reception->getLibStatut(5);
|
print $reception->getLibStatut(5);
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ ActionsOnReception=Événements sur l'réception
|
|||||||
LinkToTrackYourPackage=Lien pour le suivi de votre colis
|
LinkToTrackYourPackage=Lien pour le suivi de votre colis
|
||||||
ReceptionCreationIsDoneFromOrder=Pour le moment, la création d'une nouvelle réception se fait depuis la fiche commande fournisseur.
|
ReceptionCreationIsDoneFromOrder=Pour le moment, la création d'une nouvelle réception se fait depuis la fiche commande fournisseur.
|
||||||
ReceptionLine=Ligne d'réception
|
ReceptionLine=Ligne d'réception
|
||||||
|
RefSupplierOrder=Ref. Commande fournisseur
|
||||||
ProductQtyInCustomersOrdersRunning=Quantité de produit en commandes client ouvertes
|
ProductQtyInCustomersOrdersRunning=Quantité de produit en commandes client ouvertes
|
||||||
ProductQtyInSuppliersOrdersRunning=Quantité de produit en commandes fournisseur ouvertes
|
ProductQtyInSuppliersOrdersRunning=Quantité de produit en commandes fournisseur ouvertes
|
||||||
ProductQtyInReceptionAlreadySent=Quantité de produit en commande client ouverte déjà expédiée
|
ProductQtyInReceptionAlreadySent=Quantité de produit en commande client ouverte déjà expédiée
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ if (empty($reshook))
|
|||||||
// Create reception
|
// Create reception
|
||||||
if ($action == 'add' && $user->rights->reception->creer)
|
if ($action == 'add' && $user->rights->reception->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
$predef = '';
|
$predef = '';
|
||||||
|
|
||||||
@@ -250,7 +251,7 @@ if (empty($reshook))
|
|||||||
$object->model_pdf = GETPOST('model');
|
$object->model_pdf = GETPOST('model');
|
||||||
$object->date_delivery = $date_delivery; // Date delivery planed
|
$object->date_delivery = $date_delivery; // Date delivery planed
|
||||||
$object->fk_delivery_address = $objectsrc->fk_delivery_address;
|
$object->fk_delivery_address = $objectsrc->fk_delivery_address;
|
||||||
$object->reception_method_id = GETPOST('reception_method_id', 'int');
|
$object->shipping_method_id = GETPOST('shipping_method_id', 'int');
|
||||||
$object->tracking_number = GETPOST('tracking_number', 'alpha');
|
$object->tracking_number = GETPOST('tracking_number', 'alpha');
|
||||||
$object->ref_int = GETPOST('ref_int', 'alpha');
|
$object->ref_int = GETPOST('ref_int', 'alpha');
|
||||||
$object->note_private = GETPOST('note_private', 'none');
|
$object->note_private = GETPOST('note_private', 'none');
|
||||||
@@ -299,15 +300,7 @@ if (empty($reshook))
|
|||||||
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
|
$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))
|
|
||||||
{
|
|
||||||
// Get extra fields
|
|
||||||
foreach ($extralabelsline as $key => $value)
|
|
||||||
{
|
|
||||||
unset($_POST["options_".$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -347,7 +340,6 @@ if (empty($reshook))
|
|||||||
$sellby = GETPOST($sellby, 'alpha');
|
$sellby = GETPOST($sellby, 'alpha');
|
||||||
$eatbydate = str_replace('/','-',$eatby);
|
$eatbydate = str_replace('/','-',$eatby);
|
||||||
$sellbydate = str_replace('/','-',$sellby);
|
$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'));
|
$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i], GETPOST($comment, 'alpha'), strtotime($eatbydate),strtotime($sellbydate), GETPOST($batch, 'alpha'));
|
||||||
@@ -358,16 +350,15 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var_dump($object->lines);exit; // TODO CHECK LINES
|
|
||||||
|
|
||||||
// Fill array 'array_options' with data from add form
|
// Fill array 'array_options' with data from add form
|
||||||
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
|
||||||
|
|
||||||
if ($ret < 0) $error++;
|
if ($ret < 0) $error++;
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$ret=$object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
|
$ret=$object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
|
||||||
|
|
||||||
if ($ret <= 0)
|
if ($ret <= 0)
|
||||||
{
|
{
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
@@ -490,7 +481,7 @@ if (empty($reshook))
|
|||||||
|| $action == 'settrueWidth'
|
|| $action == 'settrueWidth'
|
||||||
|| $action == 'settrueHeight'
|
|| $action == 'settrueHeight'
|
||||||
|| $action == 'settrueDepth'
|
|| $action == 'settrueDepth'
|
||||||
|| $action == 'setreception_method_id')
|
|| $action == 'setshipping_method_id')
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@@ -506,7 +497,7 @@ if (empty($reshook))
|
|||||||
$object->size_units = GETPOST('size_units','int');
|
$object->size_units = GETPOST('size_units','int');
|
||||||
}
|
}
|
||||||
if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
|
if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth','int'));
|
||||||
if ($action == 'setreception_method_id') $object->reception_method_id = trim(GETPOST('reception_method_id','int'));
|
if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id','int'));
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@@ -584,7 +575,7 @@ if (empty($reshook))
|
|||||||
{
|
{
|
||||||
$object->fetch($id);
|
$object->fetch($id);
|
||||||
$lines = $object->lines;
|
$lines = $object->lines;
|
||||||
$line = new ReceptionLigne($db);
|
$line = new CommandeFournisseurDispatch($db);
|
||||||
|
|
||||||
$num_prod = count($lines);
|
$num_prod = count($lines);
|
||||||
for ($i = 0 ; $i < $num_prod ; $i++)
|
for ($i = 0 ; $i < $num_prod ; $i++)
|
||||||
@@ -641,7 +632,7 @@ if (empty($reshook))
|
|||||||
{
|
{
|
||||||
if ($lines[$i]->id == $line_id) // we have found line to update
|
if ($lines[$i]->id == $line_id) // we have found line to update
|
||||||
{
|
{
|
||||||
$line = new ReceptionLigne($db);
|
$line = new CommandeFournisseurDispatch($db);
|
||||||
// Extrafields Lines
|
// Extrafields Lines
|
||||||
$extrafieldsline = new ExtraFields($db);
|
$extrafieldsline = new ExtraFields($db);
|
||||||
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
|
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
|
||||||
@@ -957,7 +948,7 @@ if ($action == 'create')
|
|||||||
if ($origin == 'supplier_order') print $langs->trans('RefSupplierOrder');
|
if ($origin == 'supplier_order') print $langs->trans('RefSupplierOrder');
|
||||||
else print $langs->trans('RefSupplier');
|
else print $langs->trans('RefSupplier');
|
||||||
print '</td><td colspan="3">';
|
print '</td><td colspan="3">';
|
||||||
print '<input type="text" name="ref_customer" value="'.$object->ref_supplier.'" />';
|
print '<input type="text" name="ref_supplier" value="'.$object->ref_supplier.'" />';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
@@ -1032,7 +1023,7 @@ if ($action == 'create')
|
|||||||
print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
|
print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";
|
||||||
print '<td colspan="3">';
|
print '<td colspan="3">';
|
||||||
$recept->fetch_delivery_methods();
|
$recept->fetch_delivery_methods();
|
||||||
print $form->selectarray("reception_method_id", $recept->meths, GETPOST('reception_method_id','int'),1,0,0,"",1);
|
print $form->selectarray("shipping_method_id", $recept->meths, GETPOST('shipping_method_id','int'),1,0,0,"",1);
|
||||||
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||||
print "</td></tr>\n";
|
print "</td></tr>\n";
|
||||||
|
|
||||||
@@ -1322,14 +1313,7 @@ $numAsked ++;
|
|||||||
{
|
{
|
||||||
print '<!-- Show warehouse selection -->';
|
print '<!-- Show warehouse selection -->';
|
||||||
print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1);
|
print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1);
|
||||||
if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id)
|
|
||||||
{
|
|
||||||
//print $stock.' '.$quantityToBeDelivered;
|
|
||||||
if ($stock < $quantityToBeDelivered)
|
|
||||||
{
|
|
||||||
print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1441,6 +1425,7 @@ else if ($id || $ref)
|
|||||||
{
|
{
|
||||||
if (!empty($object->origin) && $object->origin_id > 0)
|
if (!empty($object->origin) && $object->origin_id > 0)
|
||||||
{
|
{
|
||||||
|
$object->origin = 'CommandeFournisseur';
|
||||||
$typeobject = $object->origin;
|
$typeobject = $object->origin;
|
||||||
$origin = $object->origin;
|
$origin = $object->origin;
|
||||||
$origin_id = $object->origin_id;
|
$origin_id = $object->origin_id;
|
||||||
@@ -1524,13 +1509,19 @@ else if ($id || $ref)
|
|||||||
$objectsrc=new Propal($db);
|
$objectsrc=new Propal($db);
|
||||||
$objectsrc->fetch($object->$typeobject->id);
|
$objectsrc->fetch($object->$typeobject->id);
|
||||||
}
|
}
|
||||||
|
if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->fournisseur->enabled))
|
||||||
|
{
|
||||||
|
$objectsrc=new CommandeFournisseur($db);
|
||||||
|
$objectsrc->fetch($object->$typeobject->id);
|
||||||
|
}
|
||||||
// Reception card
|
// Reception card
|
||||||
$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
|
$linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
|
||||||
$morehtmlref='<div class="refidno">';
|
$morehtmlref='<div class="refidno">';
|
||||||
// Ref customer reception
|
// Ref customer reception
|
||||||
$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->reception->creer, 'string', '', 0, 1);
|
|
||||||
$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
|
$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1);
|
||||||
|
$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1);
|
||||||
|
|
||||||
// Thirdparty
|
// Thirdparty
|
||||||
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
|
||||||
// Project
|
// Project
|
||||||
@@ -1569,7 +1560,7 @@ else if ($id || $ref)
|
|||||||
}
|
}
|
||||||
$morehtmlref.='</div>';
|
$morehtmlref.='</div>';
|
||||||
|
|
||||||
|
$object->picto = 'sending';
|
||||||
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
|
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
|
||||||
|
|
||||||
|
|
||||||
@@ -1598,6 +1589,15 @@ else if ($id || $ref)
|
|||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
}
|
}
|
||||||
|
if ($typeobject == 'CommandeFournisseur' && $object->$typeobject->id && ! empty($conf->propal->enabled))
|
||||||
|
{
|
||||||
|
print '<tr><td>';
|
||||||
|
print $langs->trans("RefSupplierOrder").'</td>';
|
||||||
|
print '<td colspan="3">';
|
||||||
|
print $objectsrc->getNomUrl(1,'reception');
|
||||||
|
print "</td>\n";
|
||||||
|
print '</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
// Date creation
|
// Date creation
|
||||||
print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
|
print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
|
||||||
@@ -1734,6 +1734,7 @@ else if ($id || $ref)
|
|||||||
|
|
||||||
// Other attributes
|
// Other attributes
|
||||||
$cols = 2;
|
$cols = 2;
|
||||||
|
|
||||||
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
|
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
@@ -1748,36 +1749,37 @@ else if ($id || $ref)
|
|||||||
// Reception method
|
// Reception method
|
||||||
print '<tr><td height="10">';
|
print '<tr><td height="10">';
|
||||||
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
print '<table class="nobordernopadding" width="100%"><tr><td>';
|
||||||
print $langs->trans('ReceptionMethod');
|
print $langs->trans('SendingMethod');
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
if ($action != 'editreception_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editreception_method_id&id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
|
if ($action != 'editshipping_method_id') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'),1).'</a></td>';
|
||||||
print '</tr></table>';
|
print '</tr></table>';
|
||||||
print '</td><td colspan="2">';
|
print '</td><td colspan="2">';
|
||||||
if ($action == 'editreception_method_id')
|
if ($action == 'editshipping_method_id')
|
||||||
{
|
{
|
||||||
print '<form name="setreception_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
|
print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="setreception_method_id">';
|
print '<input type="hidden" name="action" value="setshipping_method_id">';
|
||||||
$object->fetch_delivery_methods();
|
$object->fetch_delivery_methods();
|
||||||
print $form->selectarray("reception_method_id",$object->meths,$object->reception_method_id,1,0,0,"",1);
|
print $form->selectarray("shipping_method_id",$object->meths,$object->shipping_method_id,1,0,0,"",1);
|
||||||
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
||||||
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
|
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($object->reception_method_id > 0)
|
if ($object->shipping_method_id > 0)
|
||||||
{
|
{
|
||||||
// Get code using getLabelFromKey
|
// Get code using getLabelFromKey
|
||||||
$code=$langs->getLabelFromKey($db,$object->reception_method_id,'c_reception_mode','rowid','code');
|
$code=$langs->getLabelFromKey($db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
|
||||||
print $langs->trans("ReceptionMethod".strtoupper($code));
|
print $langs->trans("SendingMethod".strtoupper($code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
// Tracking Number
|
// Tracking Number
|
||||||
|
|
||||||
print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->reception->creer).'</td><td colspan="3">';
|
print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber",'tracking_number',$object->tracking_number,$object,$user->rights->reception->creer).'</td><td colspan="3">';
|
||||||
print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->reception->creer,'string',$object->tracking_number);
|
print $form->editfieldval("TrackingNumber",'tracking_number',$object->tracking_url,$object,$user->rights->reception->creer,'string',$object->tracking_number);
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
@@ -2057,7 +2059,7 @@ else if ($id || $ref)
|
|||||||
if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
|
if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)
|
||||||
{
|
{
|
||||||
print '<!-- case edit 1 -->';
|
print '<!-- case edit 1 -->';
|
||||||
$line = new ReceptionLigne($db);
|
$line = new CommandeFournisseurDispatch($db);
|
||||||
foreach ($lines[$i]->detail_batch as $detail_batch)
|
foreach ($lines[$i]->detail_batch as $detail_batch)
|
||||||
{
|
{
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
@@ -2239,7 +2241,7 @@ else if ($id || $ref)
|
|||||||
// Display lines extrafields
|
// Display lines extrafields
|
||||||
if (is_array($extralabelslines) && count($extralabelslines)>0) {
|
if (is_array($extralabelslines) && count($extralabelslines)>0) {
|
||||||
$colspan= empty($conf->productbatch->enabled) ? 5 : 6;
|
$colspan= empty($conf->productbatch->enabled) ? 5 : 6;
|
||||||
$line = new ReceptionLigne($db);
|
$line = new CommandeFournisseurDispatch($db);
|
||||||
$line->fetch_optionals($lines[$i]->id,$extralabelslines);
|
$line->fetch_optionals($lines[$i]->id,$extralabelslines);
|
||||||
print '<tr class="oddeven">';
|
print '<tr class="oddeven">';
|
||||||
if ($action == 'editline' && $lines[$i]->id == $line_id)
|
if ($action == 'editline' && $lines[$i]->id == $line_id)
|
||||||
|
|||||||
@@ -208,7 +208,6 @@ class Reception extends CommonObject
|
|||||||
$sql.= ", date_delivery";
|
$sql.= ", date_delivery";
|
||||||
$sql.= ", fk_soc";
|
$sql.= ", fk_soc";
|
||||||
$sql.= ", fk_projet";
|
$sql.= ", fk_projet";
|
||||||
$sql.= ", fk_address";
|
|
||||||
$sql.= ", fk_shipping_method";
|
$sql.= ", fk_shipping_method";
|
||||||
$sql.= ", tracking_number";
|
$sql.= ", tracking_number";
|
||||||
$sql.= ", weight";
|
$sql.= ", weight";
|
||||||
@@ -232,8 +231,7 @@ class Reception extends CommonObject
|
|||||||
$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
|
$sql.= ", ".($this->date_delivery>0?"'".$this->db->idate($this->date_delivery)."'":"null");
|
||||||
$sql.= ", ".$this->socid;
|
$sql.= ", ".$this->socid;
|
||||||
$sql.= ", ".$this->fk_project;
|
$sql.= ", ".$this->fk_project;
|
||||||
$sql.= ", ".($this->fk_delivery_address>0?$this->fk_delivery_address:"null");
|
$sql.= ", ".($this->shipping_method_id>0?$this->shipping_method_id:"null");
|
||||||
$sql.= ", ".($this->reception_method_id>0?$this->reception_method_id:"null");
|
|
||||||
$sql.= ", '".$this->db->escape($this->tracking_number)."'";
|
$sql.= ", '".$this->db->escape($this->tracking_number)."'";
|
||||||
$sql.= ", ".$this->weight;
|
$sql.= ", ".$this->weight;
|
||||||
$sql.= ", ".$this->sizeS; // TODO Should use this->trueDepth
|
$sql.= ", ".$this->sizeS; // TODO Should use this->trueDepth
|
||||||
@@ -249,7 +247,9 @@ class Reception extends CommonObject
|
|||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."reception");
|
||||||
@@ -269,7 +269,7 @@ class Reception extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->lines[$i]->fk_reception = $this->id;
|
$this->lines[$i]->fk_reception = $this->id;
|
||||||
|
|
||||||
if (! $this->lines[$i]->create() > 0)
|
if (! $this->lines[$i]->create($user) > 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
@@ -418,7 +418,7 @@ class Reception extends CommonObject
|
|||||||
|
|
||||||
$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
|
$sql = "SELECT e.rowid, e.ref, e.fk_soc as socid, e.date_creation, e.ref_supplier, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut";
|
||||||
$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
|
$sql.= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height";
|
||||||
$sql.= ", e.date_reception as date_reception, e.model_pdf, e.fk_address, e.date_delivery";
|
$sql.= ", e.date_reception as date_reception, e.model_pdf, e.date_delivery";
|
||||||
$sql.= ", e.fk_shipping_method, e.tracking_number";
|
$sql.= ", e.fk_shipping_method, e.tracking_number";
|
||||||
$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
|
$sql.= ", el.fk_source as origin_id, el.sourcetype as origin";
|
||||||
$sql.= ", e.note_private, e.note_public";
|
$sql.= ", e.note_private, e.note_public";
|
||||||
@@ -613,8 +613,8 @@ class Reception extends CommonObject
|
|||||||
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
||||||
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."receptiondet as ed";
|
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as edb on edb.fk_receptiondet = ed.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch_batch as edb on edb.fk_commande_fournisseur_dispatch = ed.rowid";
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
||||||
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
||||||
|
|
||||||
@@ -891,7 +891,7 @@ class Reception extends CommonObject
|
|||||||
if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
|
if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author);
|
||||||
if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
|
if (isset($this->fk_user_valid)) $this->fk_user_valid=trim($this->fk_user_valid);
|
||||||
if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
|
if (isset($this->fk_delivery_address)) $this->fk_delivery_address=trim($this->fk_delivery_address);
|
||||||
if (isset($this->reception_method_id)) $this->reception_method_id=trim($this->reception_method_id);
|
if (isset($this->shipping_method_id)) $this->shipping_method_id=trim($this->shipping_method_id);
|
||||||
if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
|
if (isset($this->tracking_number)) $this->tracking_number=trim($this->tracking_number);
|
||||||
if (isset($this->statut)) $this->statut=(int) $this->statut;
|
if (isset($this->statut)) $this->statut=(int) $this->statut;
|
||||||
if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
|
if (isset($this->trueDepth)) $this->trueDepth=trim($this->trueDepth);
|
||||||
@@ -922,8 +922,7 @@ class Reception extends CommonObject
|
|||||||
$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
|
$sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").",";
|
||||||
$sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
|
$sql.= " date_reception=".(dol_strlen($this->date_reception)!=0 ? "'".$this->db->idate($this->date_reception)."'" : 'null').",";
|
||||||
$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
|
$sql.= " date_delivery=".(dol_strlen($this->date_delivery)!=0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').",";
|
||||||
$sql.= " fk_address=".(isset($this->fk_delivery_address)?$this->fk_delivery_address:"null").",";
|
$sql.= " fk_shipping_method=".((isset($this->shipping_method_id) && $this->shipping_method_id > 0)?$this->shipping_method_id:"null").",";
|
||||||
$sql.= " fk_shipping_method=".((isset($this->reception_method_id) && $this->reception_method_id > 0)?$this->reception_method_id:"null").",";
|
|
||||||
$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
|
$sql.= " tracking_number=".(isset($this->tracking_number)?"'".$this->db->escape($this->tracking_number)."'":"null").",";
|
||||||
$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
|
$sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").",";
|
||||||
$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
|
$sql.= " height=".(($this->trueHeight != '')?$this->trueHeight:"null").",";
|
||||||
@@ -1008,9 +1007,9 @@ class Reception extends CommonObject
|
|||||||
$langs->load("agenda");
|
$langs->load("agenda");
|
||||||
|
|
||||||
// Loop on each product line to add a stock movement
|
// Loop on each product line to add a stock movement
|
||||||
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as receptiondet_id";
|
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid as commande_fournisseur_dispatch_id";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."receptiondet as ed";
|
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
||||||
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
||||||
|
|
||||||
@@ -1031,7 +1030,7 @@ class Reception extends CommonObject
|
|||||||
$lotArray = null;
|
$lotArray = null;
|
||||||
if ($conf->productbatch->enabled)
|
if ($conf->productbatch->enabled)
|
||||||
{
|
{
|
||||||
$lotArray = ReceptionLineBatch::fetchAll($this->db,$obj->receptiondet_id);
|
$lotArray = ReceptionLineBatch::fetchAll($this->db,$obj->commande_fournisseur_dispatch_id);
|
||||||
if (! is_array($lotArray))
|
if (! is_array($lotArray))
|
||||||
{
|
{
|
||||||
$error++;$this->errors[]="Error ".$this->db->lasterror();
|
$error++;$this->errors[]="Error ".$this->db->lasterror();
|
||||||
@@ -1082,7 +1081,7 @@ class Reception extends CommonObject
|
|||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."receptiondet";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch";
|
||||||
$sql.= " WHERE fk_reception = ".$this->id;
|
$sql.= " WHERE fk_reception = ".$this->id;
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
@@ -1190,174 +1189,25 @@ class Reception extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function fetch_lines()
|
function fetch_lines()
|
||||||
{
|
{
|
||||||
global $conf, $mysoc;
|
global $db;
|
||||||
// TODO: recuperer les champs du document associe a part
|
|
||||||
|
|
||||||
$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked, cd.product_type";
|
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id;
|
||||||
$sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
|
$resql = $db->query($sql);
|
||||||
$sql.= ", cd.vat_src_code, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht";
|
if(!empty($resql)){
|
||||||
$sql.= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc";
|
|
||||||
$sql.= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
|
|
||||||
$sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
|
|
||||||
$sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch";
|
|
||||||
$sql.= " FROM (".MAIN_DB_PREFIX."receptiondet as ed,";
|
|
||||||
$sql.= " ".MAIN_DB_PREFIX."commandedet as cd)";
|
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
|
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
|
||||||
$sql.= " AND ed.fk_origin_line = cd.rowid";
|
|
||||||
$sql.= " ORDER BY cd.rang, ed.fk_origin_line";
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
|
while ($obj = $resql->fetch_object()){
|
||||||
$resql = $this->db->query($sql);
|
$line = new CommandeFournisseurDispatch($db);
|
||||||
if ($resql)
|
$line->fetch($obj->rowid);
|
||||||
{
|
$line->fetch_product();
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
|
||||||
|
|
||||||
$num = $this->db->num_rows($resql);
|
$this->lines[]=$line;
|
||||||
$i = 0;
|
|
||||||
$lineindex = 0;
|
|
||||||
$originline = 0;
|
|
||||||
|
|
||||||
$this->total_ht = 0;
|
|
||||||
$this->total_tva = 0;
|
|
||||||
$this->total_ttc = 0;
|
|
||||||
$this->total_localtax1 = 0;
|
|
||||||
$this->total_localtax2 = 0;
|
|
||||||
|
|
||||||
while ($i < $num)
|
|
||||||
{
|
|
||||||
$obj = $this->db->fetch_object($resql);
|
|
||||||
|
|
||||||
if ($originline == $obj->fk_origin_line) {
|
|
||||||
$line->entrepot_id = 0; // entrepod_id in details_entrepot
|
|
||||||
$line->qty_shipped += $obj->qty_shipped;
|
|
||||||
} else {
|
|
||||||
$line = new ReceptionLigne($this->db);
|
|
||||||
$line->entrepot_id = $obj->fk_entrepot;
|
|
||||||
$line->qty_shipped = $obj->qty_shipped;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$detail_entrepot = new stdClass;
|
|
||||||
$detail_entrepot->entrepot_id = $obj->fk_entrepot;
|
|
||||||
$detail_entrepot->qty_shipped = $obj->qty_shipped;
|
|
||||||
$line->details_entrepot[] = $detail_entrepot;
|
|
||||||
|
|
||||||
$line->line_id = $obj->line_id;
|
|
||||||
$line->rowid = $obj->line_id; // TODO deprecated
|
|
||||||
$line->id = $obj->line_id;
|
|
||||||
|
|
||||||
$line->fk_origin = 'orderline';
|
|
||||||
$line->fk_origin_line = $obj->fk_origin_line;
|
|
||||||
$line->origin_line_id = $obj->fk_origin_line; // TODO deprecated
|
|
||||||
|
|
||||||
$line->fk_reception = $this->id; // id of parent
|
|
||||||
|
|
||||||
$line->product_type = $obj->product_type;
|
|
||||||
$line->fk_product = $obj->fk_product;
|
|
||||||
$line->fk_product_type = $obj->fk_product_type;
|
|
||||||
$line->ref = $obj->product_ref; // TODO deprecated
|
|
||||||
$line->product_ref = $obj->product_ref;
|
|
||||||
$line->product_label = $obj->product_label;
|
|
||||||
$line->libelle = $obj->product_label; // TODO deprecated
|
|
||||||
$line->product_tobatch = $obj->product_tobatch;
|
|
||||||
$line->label = $obj->custom_label;
|
|
||||||
$line->description = $obj->description;
|
|
||||||
$line->qty_asked = $obj->qty_asked;
|
|
||||||
$line->weight = $obj->weight;
|
|
||||||
$line->weight_units = $obj->weight_units;
|
|
||||||
$line->length = $obj->length;
|
|
||||||
$line->length_units = $obj->length_units;
|
|
||||||
$line->surface = $obj->surface;
|
|
||||||
$line->surface_units = $obj->surface_units;
|
|
||||||
$line->volume = $obj->volume;
|
|
||||||
$line->volume_units = $obj->volume_units;
|
|
||||||
|
|
||||||
$line->pa_ht = $obj->pa_ht;
|
|
||||||
|
|
||||||
// Local taxes
|
|
||||||
$localtax_array=array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx);
|
|
||||||
$localtax1_tx = get_localtax($obj->tva_tx, 1, $this->thirdparty);
|
|
||||||
$localtax2_tx = get_localtax($obj->tva_tx, 2, $this->thirdparty);
|
|
||||||
|
|
||||||
// For invoicing
|
|
||||||
$tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0
|
|
||||||
$line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements)
|
|
||||||
$line->qty = $line->qty_shipped;
|
|
||||||
$line->total_ht = $tabprice[0];
|
|
||||||
$line->total_localtax1 = $tabprice[9];
|
|
||||||
$line->total_localtax2 = $tabprice[10];
|
|
||||||
$line->total_ttc = $tabprice[2];
|
|
||||||
$line->total_tva = $tabprice[1];
|
|
||||||
$line->vat_src_code = $obj->vat_src_code;
|
|
||||||
$line->tva_tx = $obj->tva_tx;
|
|
||||||
$line->localtax1_tx = $obj->localtax1_tx;
|
|
||||||
$line->localtax2_tx = $obj->localtax2_tx;
|
|
||||||
$line->price = $obj->price;
|
|
||||||
$line->subprice = $obj->subprice;
|
|
||||||
$line->remise_percent = $obj->remise_percent;
|
|
||||||
|
|
||||||
$this->total_ht+= $tabprice[0];
|
|
||||||
$this->total_tva+= $tabprice[1];
|
|
||||||
$this->total_ttc+= $tabprice[2];
|
|
||||||
$this->total_localtax1+= $tabprice[9];
|
|
||||||
$this->total_localtax2+= $tabprice[10];
|
|
||||||
|
|
||||||
// Multicurrency
|
|
||||||
$this->fk_multicurrency = $obj->fk_multicurrency;
|
|
||||||
$this->multicurrency_code = $obj->multicurrency_code;
|
|
||||||
$this->multicurrency_subprice = $obj->multicurrency_subprice;
|
|
||||||
$this->multicurrency_total_ht = $obj->multicurrency_total_ht;
|
|
||||||
$this->multicurrency_total_tva = $obj->multicurrency_total_tva;
|
|
||||||
$this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
|
|
||||||
|
|
||||||
if ($originline != $obj->fk_origin_line)
|
|
||||||
{
|
|
||||||
$line->detail_batch = array();
|
|
||||||
}
|
|
||||||
// Eat-by date
|
|
||||||
if (! empty($conf->productbatch->enabled) && $obj->line_id > 0)
|
|
||||||
{
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionbatch.class.php';
|
|
||||||
|
|
||||||
$newdetailbatch = ReceptionLineBatch::fetchAll($this->db,$obj->line_id);
|
|
||||||
if (is_array($newdetailbatch))
|
|
||||||
{
|
|
||||||
if ($originline != $obj->fk_origin_line)
|
|
||||||
{
|
|
||||||
$line->detail_batch = $newdetailbatch;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$line->detail_batch = array_merge($line->detail_batch, $newdetailbatch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($originline != $obj->fk_origin_line)
|
|
||||||
{
|
|
||||||
$this->lines[$lineindex] = $line;
|
|
||||||
$lineindex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$line->total_ht += $tabprice[0];
|
|
||||||
$line->total_localtax1 += $tabprice[9];
|
|
||||||
$line->total_localtax2 += $tabprice[10];
|
|
||||||
$line->total_ttc += $tabprice[2];
|
|
||||||
$line->total_tva += $tabprice[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
$originline = $obj->fk_origin_line;
|
|
||||||
}
|
|
||||||
$this->db->free($resql);
|
|
||||||
return 1;
|
return 1;
|
||||||
|
}else {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->error();
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1398,7 +1248,7 @@ class Reception extends CommonObject
|
|||||||
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
|
||||||
$linkend='</a>';
|
$linkend='</a>';
|
||||||
|
|
||||||
$picto='reception';
|
$picto='sending';
|
||||||
|
|
||||||
if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
|
if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend);
|
||||||
if ($withpicto && $withpicto != 2) $result.=' ';
|
if ($withpicto && $withpicto != 2) $result.=' ';
|
||||||
@@ -1703,11 +1553,11 @@ class Reception extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function GetUrlTrackingStatus($value='')
|
function GetUrlTrackingStatus($value='')
|
||||||
{
|
{
|
||||||
if (! empty($this->reception_method_id))
|
if (! empty($this->shipping_method_id))
|
||||||
{
|
{
|
||||||
$sql = "SELECT em.code, em.tracking";
|
$sql = "SELECT em.code, em.tracking";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_reception_mode as em";
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_reception_mode as em";
|
||||||
$sql.= " WHERE em.rowid = ".$this->reception_method_id;
|
$sql.= " WHERE em.rowid = ".$this->shipping_method_id;
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@@ -1793,8 +1643,8 @@ class Reception extends CommonObject
|
|||||||
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
||||||
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."receptiondet as ed";
|
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as edb on edb.fk_receptiondet = ed.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch_batch as edb on edb.fk_commande_fournisseur_dispatch = ed.rowid";
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
||||||
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
||||||
|
|
||||||
@@ -1958,8 +1808,8 @@ class Reception extends CommonObject
|
|||||||
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
||||||
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."receptiondet as ed";
|
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as edb on edb.fk_receptiondet = ed.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch_batch as edb on edb.fk_commande_fournisseur_dispatch = ed.rowid";
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
||||||
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
||||||
|
|
||||||
@@ -2093,8 +1943,8 @@ class Reception extends CommonObject
|
|||||||
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
$sql.= " ed.rowid, ed.qty, ed.fk_entrepot,";
|
||||||
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
$sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."receptiondet as ed";
|
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as ed";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as edb on edb.fk_receptiondet = ed.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur_dispatch_batch as edb on edb.fk_commande_fournisseur_dispatch = ed.rowid";
|
||||||
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
$sql.= " WHERE ed.fk_reception = ".$this->id;
|
||||||
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
$sql.= " AND cd.rowid = ed.fk_origin_line";
|
||||||
|
|
||||||
@@ -2235,469 +2085,3 @@ class Reception extends CommonObject
|
|||||||
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
|
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Classe de gestion des lignes de bons d'reception
|
|
||||||
*/
|
|
||||||
class ReceptionLigne extends CommonObjectLine
|
|
||||||
{
|
|
||||||
public $element='receptiondet';
|
|
||||||
public $table_element='receptiondet';
|
|
||||||
|
|
||||||
public $fk_origin_line;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id of reception
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $fk_reception;
|
|
||||||
|
|
||||||
var $db;
|
|
||||||
|
|
||||||
// From llx_receptiondet
|
|
||||||
var $qty;
|
|
||||||
var $qty_shipped;
|
|
||||||
var $fk_product;
|
|
||||||
var $detail_batch;
|
|
||||||
/**
|
|
||||||
* Id of warehouse
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $entrepot_id;
|
|
||||||
|
|
||||||
|
|
||||||
// From llx_commandedet or llx_propaldet
|
|
||||||
var $qty_asked;
|
|
||||||
public $product_ref;
|
|
||||||
public $product_label;
|
|
||||||
public $product_desc;
|
|
||||||
|
|
||||||
|
|
||||||
// Invoicing
|
|
||||||
var $remise_percent;
|
|
||||||
var $total_ht; // Total net of tax
|
|
||||||
var $total_ttc; // Total with tax
|
|
||||||
var $total_tva; // Total VAT
|
|
||||||
var $total_localtax1; // Total Local tax 1
|
|
||||||
var $total_localtax2; // Total Local tax 2
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see fk_origin_line
|
|
||||||
*/
|
|
||||||
var $origin_line_id;
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see product_ref
|
|
||||||
*/
|
|
||||||
var $ref;
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @see product_label
|
|
||||||
*/
|
|
||||||
var $libelle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param DoliDB $db Database handler
|
|
||||||
*/
|
|
||||||
function __construct($db)
|
|
||||||
{
|
|
||||||
$this->db=$db;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load line reception
|
|
||||||
*
|
|
||||||
* @param int $rowid Id line order
|
|
||||||
* @return int <0 if KO, >0 if OK
|
|
||||||
*/
|
|
||||||
function fetch($rowid)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT ed.rowid, ed.fk_reception, ed.fk_entrepot, ed.fk_origin_line, ed.qty, ed.rang';
|
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed';
|
|
||||||
$sql.= ' WHERE ed.rowid = '.$rowid;
|
|
||||||
$result = $this->db->query($sql);
|
|
||||||
if ($result)
|
|
||||||
{
|
|
||||||
$objp = $this->db->fetch_object($result);
|
|
||||||
$this->id = $objp->rowid;
|
|
||||||
$this->fk_reception = $objp->fk_reception;
|
|
||||||
$this->entrepot_id = $objp->fk_entrepot;
|
|
||||||
$this->fk_origin_line = $objp->fk_origin_line;
|
|
||||||
$this->qty = $objp->qty;
|
|
||||||
$this->rang = $objp->rang;
|
|
||||||
|
|
||||||
$this->db->free($result);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->errors[] = $this->db->lasterror();
|
|
||||||
$this->error = $this->db->lasterror();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert line into database
|
|
||||||
*
|
|
||||||
* @param User $user User that modify
|
|
||||||
* @param int $notrigger 1 = disable triggers
|
|
||||||
* @return int <0 if KO, line id >0 if OK
|
|
||||||
*/
|
|
||||||
function insert($user=null, $notrigger=0)
|
|
||||||
{
|
|
||||||
global $langs, $conf;
|
|
||||||
|
|
||||||
$error=0;
|
|
||||||
|
|
||||||
// Check parameters
|
|
||||||
if (empty($this->fk_reception) || empty($this->fk_origin_line) || ! is_numeric($this->qty))
|
|
||||||
{
|
|
||||||
$this->error = 'ErrorMandatoryParametersNotProvided';
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// Clean parameters
|
|
||||||
if (empty($this->entrepot_id)) $this->entrepot_id='null';
|
|
||||||
|
|
||||||
$this->db->begin();
|
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."receptiondet (";
|
|
||||||
$sql.= "fk_reception";
|
|
||||||
$sql.= ", fk_entrepot";
|
|
||||||
$sql.= ", fk_origin_line";
|
|
||||||
$sql.= ", qty";
|
|
||||||
$sql.= ") VALUES (";
|
|
||||||
$sql.= $this->fk_reception;
|
|
||||||
$sql.= ", ".$this->entrepot_id;
|
|
||||||
$sql.= ", ".$this->fk_origin_line;
|
|
||||||
$sql.= ", ".$this->qty;
|
|
||||||
$sql.= ")";
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."receptiondet");
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->insertExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error && ! $notrigger)
|
|
||||||
{
|
|
||||||
// Call trigger
|
|
||||||
$result=$this->call_trigger('LINERECEPTION_INSERT',$user);
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
// End call triggers
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
$this->db->commit();
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($this->errors as $errmsg)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
|
|
||||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1*$error;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete reception line.
|
|
||||||
*
|
|
||||||
* @param User $user User that modify
|
|
||||||
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
|
||||||
* @return int >0 if OK, <0 if KO
|
|
||||||
*/
|
|
||||||
function delete($user = null, $notrigger = 0)
|
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$error=0;
|
|
||||||
|
|
||||||
$this->db->begin();
|
|
||||||
|
|
||||||
// delete batch reception line
|
|
||||||
if ($conf->productbatch->enabled)
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."receptiondet_batch";
|
|
||||||
$sql.= " WHERE fk_receptiondet = ".$this->id;
|
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->db->lasterror()." - sql=$sql";
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."receptiondet";
|
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
|
||||||
|
|
||||||
if (! $error && $this->db->query($sql))
|
|
||||||
{
|
|
||||||
// Remove extrafields
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->deleteExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->error;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! $error && ! $notrigger)
|
|
||||||
{
|
|
||||||
// Call trigger
|
|
||||||
$result=$this->call_trigger('LINERECEPTION_DELETE',$user);
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->error;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
// End call triggers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->db->lasterror()." - sql=$sql";
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $error) {
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach($this->errors as $errmsg)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
|
|
||||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1*$error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update a line in database
|
|
||||||
*
|
|
||||||
* @param User $user User that modify
|
|
||||||
* @param int $notrigger 1 = disable triggers
|
|
||||||
* @return int < 0 if KO, > 0 if OK
|
|
||||||
*/
|
|
||||||
function update($user = null, $notrigger = 0)
|
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$error=0;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty");
|
|
||||||
|
|
||||||
$this->db->begin();
|
|
||||||
|
|
||||||
// Clean parameters
|
|
||||||
if (empty($this->qty)) $this->qty=0;
|
|
||||||
$qty=price2num($this->qty);
|
|
||||||
$remainingQty = 0;
|
|
||||||
$batch = null;
|
|
||||||
$batch_id = null;
|
|
||||||
$reception_batch_id = null;
|
|
||||||
if (is_array($this->detail_batch)) // array of ReceptionLineBatch
|
|
||||||
{
|
|
||||||
if (count($this->detail_batch) > 1)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR);
|
|
||||||
$this->errors[]='ErrorBadParameters';
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$batch = $this->detail_batch[0]->batch;
|
|
||||||
$batch_id = $this->detail_batch[0]->fk_origin_stock;
|
|
||||||
$reception_batch_id = $this->detail_batch[0]->id;
|
|
||||||
if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
|
|
||||||
$this->errors[]='ErrorBadParameters';
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
$qty = price2num($this->detail_batch[0]->dluo_qty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (! empty($this->detail_batch))
|
|
||||||
{
|
|
||||||
$batch = $this->detail_batch->batch;
|
|
||||||
$batch_id = $this->detail_batch->fk_origin_stock;
|
|
||||||
$reception_batch_id = $this->detail_batch->id;
|
|
||||||
if ($this->entrepot_id != $this->detail_batch->entrepot_id)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR);
|
|
||||||
$this->errors[]='ErrorBadParameters';
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
$qty = price2num($this->detail_batch->dluo_qty);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check parameters
|
|
||||||
if (! isset($this->id) || ! isset($this->entrepot_id))
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR);
|
|
||||||
$this->errors[]='ErrorMandatoryParametersNotProvided';
|
|
||||||
$error++;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update lot
|
|
||||||
|
|
||||||
if (! empty($batch) && $conf->productbatch->enabled)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::update reception batch id=$reception_batch_id, batch_id=$batch_id, batch=$batch");
|
|
||||||
|
|
||||||
if (empty($batch_id) || empty($this->fk_product)) {
|
|
||||||
dol_syslog(get_class($this).'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR);
|
|
||||||
$this->errors[]='ErrorMandatoryParametersNotProvided';
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch remaining lot qty
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionbatch.class.php';
|
|
||||||
if (! $error && ($lotArray = ReceptionLineBatch::fetchAll($this->db, $this->id)) < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->db->lasterror()." - ReceptionLineBatch::fetchAll";
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// caculate new total line qty
|
|
||||||
foreach ($lotArray as $lot)
|
|
||||||
{
|
|
||||||
if ($reception_batch_id != $lot->id)
|
|
||||||
{
|
|
||||||
$remainingQty += $lot->dluo_qty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$qty += $remainingQty;
|
|
||||||
|
|
||||||
//fetch lot details
|
|
||||||
|
|
||||||
// fetch from product_lot
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
|
|
||||||
$lot = new Productlot($this->db);
|
|
||||||
if ($lot->fetch(0,$this->fk_product,$batch) < 0)
|
|
||||||
{
|
|
||||||
$this->errors[] = $lot->errors;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
if (! $error && ! empty($reception_batch_id))
|
|
||||||
{
|
|
||||||
// delete lot reception line
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."receptiondet_batch";
|
|
||||||
$sql.= " WHERE fk_receptiondet = ".$this->id;
|
|
||||||
$sql.= " AND rowid = ".$reception_batch_id;
|
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->db->lasterror()." - sql=$sql";
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! $error && $this->detail_batch->dluo_qty > 0)
|
|
||||||
{
|
|
||||||
// create lot reception line
|
|
||||||
if (isset($lot->id))
|
|
||||||
{
|
|
||||||
$receptionLot = new ReceptionLineBatch($this->db);
|
|
||||||
$receptionLot->batch = $lot->batch;
|
|
||||||
$receptionLot->eatby = $lot->eatby;
|
|
||||||
$receptionLot->sellby = $lot->sellby;
|
|
||||||
$receptionLot->entrepot_id = $this->detail_batch->entrepot_id;
|
|
||||||
$receptionLot->dluo_qty = $this->detail_batch->dluo_qty;
|
|
||||||
$receptionLot->fk_origin_stock = $batch_id;
|
|
||||||
if ($receptionLot->create($this->id) < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$receptionLot->errors;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! $error)
|
|
||||||
{
|
|
||||||
// update line
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
|
|
||||||
$sql.= " fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id : 'null');
|
|
||||||
$sql.= " , qty = ".$qty;
|
|
||||||
$sql.= " WHERE rowid = ".$this->id;
|
|
||||||
|
|
||||||
if (!$this->db->query($sql))
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->db->lasterror()." - sql=$sql";
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
|
|
||||||
{
|
|
||||||
$result=$this->insertExtraFields();
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->error;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (! $error && ! $notrigger)
|
|
||||||
{
|
|
||||||
// Call trigger
|
|
||||||
$result=$this->call_trigger('LINERECEPTION_UPDATE',$user);
|
|
||||||
if ($result < 0)
|
|
||||||
{
|
|
||||||
$this->errors[]=$this->error;
|
|
||||||
$error++;
|
|
||||||
}
|
|
||||||
// End call triggers
|
|
||||||
}
|
|
||||||
if (!$error) {
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach($this->errors as $errmsg)
|
|
||||||
{
|
|
||||||
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
|
|
||||||
$this->error.=($this->error?', '.$errmsg:$errmsg);
|
|
||||||
}
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1*$error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user