Merge pull request #5586 from atm-florian/dev_NEW_ClassOrderDeliverStatusOnStockVentil
NEW : Add workflow to calculated supplier order status on stock dispatch
This commit is contained in:
commit
126d9ae6bf
@ -73,12 +73,22 @@ if($action)
|
||||
|| $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER'
|
||||
|| $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')
|
||||
{
|
||||
//Use variable cause empty(GETPOST()) do not work with php version < 5.4
|
||||
$valdispatch=GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha');
|
||||
|
||||
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity);
|
||||
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity);
|
||||
$res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity);
|
||||
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity);
|
||||
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity);
|
||||
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity);
|
||||
if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $valdispatch,'chaine',0,'',$conf->entity);
|
||||
if (empty($valdispatch)) {
|
||||
$res=dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", '','chaine',0,'',$conf->entity);
|
||||
}
|
||||
}
|
||||
|
||||
if($action == 'SUPPLIER_ORDER_USE_DISPATCH_STATUS') {
|
||||
$res = dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", GETPOST('SUPPLIER_ORDER_USE_DISPATCH_STATUS','alpha'),'chaine',0,'',$conf->entity);
|
||||
}
|
||||
|
||||
if($action == 'STOCK_USE_VIRTUAL_STOCK') {
|
||||
@ -163,7 +173,7 @@ if (! empty($conf->facture->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -183,7 +193,7 @@ if (! empty($conf->commande->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -205,7 +215,7 @@ if (! empty($conf->expedition->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -225,7 +235,7 @@ if (! empty($conf->expedition->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -267,7 +277,7 @@ if (! empty($conf->fournisseur->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -288,7 +298,7 @@ if (! empty($conf->fournisseur->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
$found++;
|
||||
@ -308,9 +318,30 @@ if (! empty($conf->fournisseur->enabled))
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
|
||||
if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
|
||||
$var=!$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td width="60%">'.$langs->trans("UseDispatchStatus").'</td>';
|
||||
print '<td width="160" align="right">';
|
||||
if (! empty($conf->fournisseur->enabled))
|
||||
{
|
||||
print "<form method=\"post\" action=\"stock.php\">";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print "<input type=\"hidden\" name=\"action\" value=\"SUPPLIER_ORDER_USE_DISPATCH_STATUS\">";
|
||||
print $form->selectyesno("SUPPLIER_ORDER_USE_DISPATCH_STATUS",$conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS,1,$disabled);
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"'.$disabled.'>';
|
||||
print "</form>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name"));
|
||||
}
|
||||
print "</td>\n</tr>\n";
|
||||
}
|
||||
$found++;
|
||||
|
||||
/*if (! $found)
|
||||
@ -446,13 +477,13 @@ print '<br>';
|
||||
|
||||
/* I keep the option/feature, but hidden to end users for the moment. If feature is used by module, no need to have users see it.
|
||||
If not used by a module, I still need to understand in which case user may need this now we can set rule on product page.
|
||||
if ($conf->global->PRODUIT_SOUSPRODUITS)
|
||||
if ($conf->global->PRODUIT_SOUSPRODUITS)
|
||||
{
|
||||
$var=!$var;
|
||||
|
||||
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td width="60%">'.$langs->trans("IndependantSubProductStock").'</td>';
|
||||
|
||||
|
||||
print '<td width="160" align="right">';
|
||||
print "<form method=\"post\" action=\"stock.php\">";
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
|
||||
@ -126,7 +126,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
public $multicurrency_total_ht;
|
||||
public $multicurrency_total_tva;
|
||||
public $multicurrency_total_ttc;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@ -255,7 +255,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$this->multicurrency_total_ht = $obj->multicurrency_total_ht;
|
||||
$this->multicurrency_total_tva = $obj->multicurrency_total_tva;
|
||||
$this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
|
||||
|
||||
|
||||
$this->extraparams = (array) json_decode($obj->extraparams, true);
|
||||
|
||||
$this->db->free($resql);
|
||||
@ -330,7 +330,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$line->date_start = $this->db->jdate($objp->date_start);
|
||||
$line->date_end = $this->db->jdate($objp->date_end);
|
||||
$line->fk_unit = $objp->fk_unit;
|
||||
|
||||
|
||||
// Multicurrency
|
||||
$line->fk_multicurrency = $objp->fk_multicurrency;
|
||||
$line->multicurrency_code = $objp->multicurrency_code;
|
||||
@ -338,7 +338,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$line->multicurrency_total_ht = $objp->multicurrency_total_ht;
|
||||
$line->multicurrency_total_tva = $objp->multicurrency_total_tva;
|
||||
$line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
|
||||
|
||||
|
||||
$this->special_code = $objp->special_code;
|
||||
$this->fk_parent_line = $objp->fk_parent_line;
|
||||
|
||||
@ -513,7 +513,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$billedtext='';
|
||||
//if ($statut==5 && $this->billed == 1) $statut = 8;
|
||||
if ($billed == 1) $billedtext=$langs->trans("Billed");
|
||||
|
||||
|
||||
// List of language codes for status
|
||||
$statutshort[0] = 'StatusOrderDraftShort';
|
||||
$statutshort[1] = 'StatusOrderValidatedShort';
|
||||
@ -678,7 +678,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
{
|
||||
$error=0;
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1';
|
||||
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ';
|
||||
if ($this->db->query($sql))
|
||||
@ -690,11 +690,11 @@ class CommandeFournisseur extends CommonOrder
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->billed=1;
|
||||
|
||||
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
@ -707,7 +707,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
|
||||
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
@ -754,7 +754,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
// Do we have to change status now ? (If double approval is required and first approval, we keep status to 1 = validated)
|
||||
$movetoapprovestatus=true;
|
||||
$comment='';
|
||||
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
|
||||
$sql.= " SET ref='".$this->db->escape($num)."',";
|
||||
if (empty($secondlevel)) // standard or first level approval
|
||||
@ -763,7 +763,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$sql.= " fk_user_approve = ".$user->id;
|
||||
if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)
|
||||
{
|
||||
if (empty($this->user_approve_id2))
|
||||
if (empty($this->user_approve_id2))
|
||||
{
|
||||
$movetoapprovestatus=false; // second level approval not done
|
||||
$comment=' (first level)';
|
||||
@ -830,7 +830,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
if (! $error)
|
||||
{
|
||||
$this->ref = $this->newref;
|
||||
|
||||
|
||||
if ($movetoapprovestatus) $this->statut = 2;
|
||||
else $this->statut = 1;
|
||||
if (empty($secondlevel)) // standard or first level approval
|
||||
@ -1009,7 +1009,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$this->statut = 3;
|
||||
$this->methode_commande_id = $methode;
|
||||
$this->date_commande = $this->db->idate($date);
|
||||
|
||||
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('ORDER_SUPPLIER_SUBMIT',$user);
|
||||
if ($result < 0) $error++;
|
||||
@ -1021,7 +1021,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$this->error = $this->db->lasterror();
|
||||
$this->errors[] = $this->db->lasterror();
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -1070,7 +1070,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$this->fk_multicurrency = 0;
|
||||
$this->multicurrency_tx = 1;
|
||||
}
|
||||
|
||||
|
||||
// We set order into draft status
|
||||
$this->brouillon = 1;
|
||||
|
||||
@ -1103,7 +1103,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$sql.= ", '".$this->db->escape($this->note_public)."'";
|
||||
$sql.= ", ".$conf->entity;
|
||||
$sql.= ", ".$this->socid;
|
||||
$sql.= ", ".($this->fk_project > 0 ? $this->fk_project : "null");
|
||||
$sql.= ", ".($this->fk_project > 0 ? $this->fk_project : "null");
|
||||
$sql.= ", '".$this->db->idate($now)."'";
|
||||
$sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null");
|
||||
$sql.= ", ".$user->id;
|
||||
@ -1407,7 +1407,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
|
||||
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc,$this->thirdparty);
|
||||
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
|
||||
|
||||
|
||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
@ -1419,7 +1419,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
|
||||
|
||||
$localtax1_type=$localtaxes_type[0];
|
||||
$localtax2_type=$localtaxes_type[2];
|
||||
|
||||
@ -1952,7 +1952,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$result=$this->call_trigger('ORDER_SUPPLIER_RECEIVE',$user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -2211,7 +2211,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
|
||||
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc, $this->thirdparty);
|
||||
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
|
||||
|
||||
|
||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
@ -2223,7 +2223,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
|
||||
|
||||
$localtax1_type=$localtaxes_type[0];
|
||||
$localtax2_type=$localtaxes_type[2];
|
||||
|
||||
@ -2405,7 +2405,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$this->id = $obj->rowid;
|
||||
if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author;
|
||||
if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author;
|
||||
if ($obj->fk_user_valid) $this->user_validation_id = $obj->fk_user_valid;
|
||||
if ($obj->fk_user_modif) $this->user_modification_id =$obj->fk_user_modif;
|
||||
if ($obj->fk_user_approve) $this->user_approve_id = $obj->fk_user_approve;
|
||||
@ -2424,7 +2424,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Charge indicateurs this->nb de tableau de bord
|
||||
*
|
||||
@ -2660,15 +2660,15 @@ class CommandeFournisseur extends CommonOrder
|
||||
public function hasDelay()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
if (empty($this->date_delivery) && ! empty($this->date_livraison)) $this->date_delivery = $this->date_livraison; // For backward compatibility
|
||||
|
||||
|
||||
$now = dol_now();
|
||||
$date_to_test = empty($this->date_delivery) ? $this->date_commande : $this->date_delivery;
|
||||
|
||||
|
||||
return ($this->statut > 0 && $this->statut < 4) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the customer delayed info
|
||||
*
|
||||
@ -2677,15 +2677,72 @@ class CommandeFournisseur extends CommonOrder
|
||||
public function showDelay()
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
|
||||
if (empty($this->date_delivery) && ! empty($this->date_livraison)) $this->date_delivery = $this->date_livraison; // For backward compatibility
|
||||
|
||||
|
||||
if (empty($this->date_delivery)) $text=$langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day');
|
||||
else $text=$text=$langs->trans("DeliveryDate").' '.dol_print_date($this->date_delivery, 'day');
|
||||
$text.=' '.($conf->commande->fournisseur->warning_delay>0?'+':'-').' '.round(abs($conf->commande->fournisseur->warning_delay)/3600/24,1).' '.$langs->trans("days").' < '.$langs->trans("Today");
|
||||
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calc status regarding dispatch stock
|
||||
*
|
||||
* @param User $user User action
|
||||
* @return int <0 si ko, >0 si ok
|
||||
*/
|
||||
public function calcAndSetStatusDispatch(User $user) {
|
||||
global $conf;
|
||||
|
||||
if (! empty($conf->commande->enabled) && ! empty($conf->fournisseur->enabled))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
|
||||
|
||||
$qtydelivered=array();
|
||||
$qtywished=array();
|
||||
|
||||
$supplierorderdispatch = new CommandeFournisseurDispatch($this->db);
|
||||
$filter=array('t.fk_commande'=>$this->id);
|
||||
if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
|
||||
$filter['t.status']=1;
|
||||
}
|
||||
$ret=$supplierorderdispatch->fetchAll('','',0,0,$filter);
|
||||
if ($ret<0) {
|
||||
$this->error=$supplierorderdispatch->error; $this->errors=$supplierorderdispatch->errors;
|
||||
return $ret;
|
||||
} else {
|
||||
if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) {
|
||||
//Build array with quantity deliverd by product
|
||||
foreach($supplierorderdispatch->lines as $line) {
|
||||
$qtydelivered[$line->fk_product]+=$line->qty;
|
||||
}
|
||||
foreach($this->lines as $line) {
|
||||
$qtywished[$line->fk_product]+=$line->qty;
|
||||
}
|
||||
//Compare array
|
||||
$diff_array=array_diff_assoc($qtydelivered,$qtywished);
|
||||
if (count($diff_array)==0) {
|
||||
//No diff => mean everythings is received
|
||||
$ret=$this->setStatus($user,5);
|
||||
if ($ret<0) {
|
||||
$this->error=$object->error; $this->errors=$object->errors;
|
||||
}
|
||||
} else {
|
||||
//Diff => received partially
|
||||
$ret=$this->setStatus($user,4);
|
||||
if ($ret<0) {
|
||||
$this->error=$object->error; $this->errors=$object->errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2883,7 +2940,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
|
||||
$this->fk_multicurrency = 0;
|
||||
$this->multicurrency_tx = 1;
|
||||
}
|
||||
|
||||
|
||||
// Check parameters
|
||||
if ($this->product_type < 0) return -1;
|
||||
|
||||
|
||||
@ -34,27 +34,28 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php");
|
||||
*/
|
||||
class CommandeFournisseurDispatch extends CommonObject
|
||||
{
|
||||
var $db; //!< To store db handler
|
||||
var $error; //!< To return error code (or message)
|
||||
var $errors=array(); //!< To return several error codes (or messages)
|
||||
var $element='commandefournisseurdispatch'; //!< Id that identify managed objects
|
||||
var $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored
|
||||
public $db; //!< To store db handler
|
||||
public $error; //!< To return error code (or message)
|
||||
public $errors=array(); //!< To return several error codes (or messages)
|
||||
public $element='commandefournisseurdispatch'; //!< Id that identify managed objects
|
||||
public $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored
|
||||
public $lines=array();
|
||||
|
||||
var $id;
|
||||
public $id;
|
||||
|
||||
var $fk_commande;
|
||||
var $fk_product;
|
||||
var $fk_commandefourndet;
|
||||
var $qty;
|
||||
var $fk_entrepot;
|
||||
var $fk_user;
|
||||
var $datec='';
|
||||
var $comment;
|
||||
var $status;
|
||||
var $tms='';
|
||||
var $batch;
|
||||
var $eatby='';
|
||||
var $sellby='';
|
||||
public $fk_commande;
|
||||
public $fk_product;
|
||||
public $fk_commandefourndet;
|
||||
public $qty;
|
||||
public $fk_entrepot;
|
||||
public $fk_user;
|
||||
public $datec='';
|
||||
public $comment;
|
||||
public $status;
|
||||
public $tms='';
|
||||
public $batch;
|
||||
public $eatby='';
|
||||
public $sellby='';
|
||||
|
||||
|
||||
|
||||
@ -539,4 +540,100 @@ class CommandeFournisseurDispatch extends CommonObject
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load object in memory from the database
|
||||
*
|
||||
* @param string $sortorder Sort Order
|
||||
* @param string $sortfield Sort field
|
||||
* @param int $limit offset limit
|
||||
* @param int $offset offset limit
|
||||
* @param array $filter filter array
|
||||
* @param string $filtermode filter mode (AND or OR)
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
|
||||
{
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
|
||||
$sql.= " t.fk_commande,";
|
||||
$sql.= " t.fk_product,";
|
||||
$sql.= " t.fk_commandefourndet,";
|
||||
$sql.= " t.qty,";
|
||||
$sql.= " t.fk_entrepot,";
|
||||
$sql.= " t.fk_user,";
|
||||
$sql.= " t.datec,";
|
||||
$sql.= " t.comment,";
|
||||
$sql.= " t.status,";
|
||||
$sql.= " t.tms,";
|
||||
$sql.= " t.batch,";
|
||||
$sql.= " t.eatby,";
|
||||
$sql.= " t.sellby";
|
||||
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
|
||||
|
||||
// Manage filter
|
||||
$sqlwhere = array();
|
||||
if (count($filter) > 0) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if ($key=='t.comment') {
|
||||
$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
|
||||
} elseif ($key=='t.datec' || $key=='t.tms' || $key=='t.eatby' || $key=='t.sellby' || $key=='t.batch') {
|
||||
$sqlwhere [] = $key . ' = \'' . $this->db->escape($value) . '\'';
|
||||
} else {
|
||||
$sqlwhere [] = $key . ' = ' . $this->db->escape($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($sqlwhere) > 0) {
|
||||
$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
|
||||
}
|
||||
|
||||
if (!empty($sortfield)) {
|
||||
$sql .= $this->db->order($sortfield,$sortorder);
|
||||
}
|
||||
if (!empty($limit)) {
|
||||
$sql .= ' ' . $this->db->plimit($limit + 1, $offset);
|
||||
}
|
||||
$this->lines = array();
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $this->db->num_rows($resql);
|
||||
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
$line = new self($this->db);
|
||||
|
||||
$line->id = $obj->rowid;
|
||||
|
||||
$line->fk_commande = $obj->fk_commande;
|
||||
$line->fk_product = $obj->fk_product;
|
||||
$line->fk_commandefourndet = $obj->fk_commandefourndet;
|
||||
$line->qty = $obj->qty;
|
||||
$line->fk_entrepot = $obj->fk_entrepot;
|
||||
$line->fk_user = $obj->fk_user;
|
||||
$line->datec = $this->db->jdate($obj->datec);
|
||||
$line->comment = $obj->comment;
|
||||
$line->status = $obj->status;
|
||||
$line->tms = $this->db->jdate($obj->tms);
|
||||
$line->batch = $obj->batch;
|
||||
$line->eatby = $this->db->jdate($obj->eatby);
|
||||
$line->sellby = $this->db->jdate($obj->sellby);
|
||||
|
||||
$this->lines[$line->id] = $line;
|
||||
}
|
||||
$this->db->free($resql);
|
||||
|
||||
return $num;
|
||||
} else {
|
||||
$this->errors[] = 'Error ' . $this->db->lasterror();
|
||||
dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
|
||||
|
||||
return - 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -132,3 +132,4 @@ OpenAll=Open for all actions
|
||||
OpenInternal=Open for internal actions
|
||||
OpenShipping=Open for shippings
|
||||
OpenDispatch=Open for dispatch
|
||||
UseDispatchStatus=Use dispatch status (aprouve/refuse)
|
||||
|
||||
@ -9,4 +9,4 @@ descWORKFLOW_ORDER_AUTOCREATE_INVOICE=Automatically create a customer invoice af
|
||||
descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer order is set to paid
|
||||
descWORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER=Classify linked source customer order(s) to billed when customer invoice is set to paid
|
||||
descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER=Classify linked source customer order(s) to billed when customer invoice is validated
|
||||
descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer invoice is validated
|
||||
descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer invoice is validated
|
||||
Loading…
Reference in New Issue
Block a user