taking account @eldy remarks
This commit is contained in:
parent
a39290022f
commit
0780188f4e
@ -82,11 +82,6 @@ if($action)
|
||||
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", $valdispatch,'chaine',0,'',$conf->entity);
|
||||
if ($conf->workflow->enabled && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_RECEIPT_ORDER)) {
|
||||
if (empty($valdispatch)) {
|
||||
$res=dolibarr_set_const($db, "WORKFLOW_ORDER_CLASSIFY_RECEIPT_ORDER", '','chaine',0,'',$conf->entity);
|
||||
}
|
||||
}
|
||||
if (empty($valdispatch)) {
|
||||
$res=dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", '','chaine',0,'',$conf->entity);
|
||||
}
|
||||
|
||||
@ -80,7 +80,6 @@ $workflowcodes=array(
|
||||
// For the following 2 options, if module invoice is disabled, they does not exists, so "Classify billed" for order must be done manually from order card.
|
||||
'WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER'=>array('family'=>'classify', 'position'=>40, 'enabled'=>'! empty($conf->facture->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'bill','warning'=>'WarningCloseAlways'),
|
||||
'WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER'=>array('family'=>'classify', 'position'=>50, 'enabled'=>'! empty($conf->facture->enabled) && ! empty($conf->commande->enabled)', 'picto'=>'bill','warning'=>'WarningCloseAlways'),
|
||||
'WORKFLOW_SUPPLIER_ORDER_CLASSIFY_RECEIPT_ORDER'=>array('family'=>'classify', 'position'=>50, 'enabled'=>'! empty($conf->fournisseur->enabled) && ! empty($conf->commande->enabled) && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)', 'picto'=>'order'),
|
||||
);
|
||||
|
||||
if (! empty($conf->modules_parts['workflow']) && is_array($conf->modules_parts['workflow']))
|
||||
|
||||
@ -159,59 +159,6 @@ class InterfaceWorkflowManager extends DolibarrTriggers
|
||||
}
|
||||
}
|
||||
|
||||
// classify supplier order delivery status
|
||||
if ($action == 'ORDER_SUPPLIER_DISPATCH')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
|
||||
if (! empty($conf->commande->enabled) && ! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_SUPPLIER_ORDER_CLASSIFY_RECEIPT_ORDER))
|
||||
{
|
||||
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'=>$object->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($object->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=$object->setStatus($user,5);
|
||||
if ($ret<0) {
|
||||
$this->error=$object->error; $this->errors=$object->errors;
|
||||
}
|
||||
} else {
|
||||
//Diff => received partially
|
||||
$ret=$object->setStatus($user,4);
|
||||
if ($ret<0) {
|
||||
$this->error=$object->error; $this->errors=$object->errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3056,5 +3056,62 @@ class CommandeFournisseurLigne extends CommonOrderLine
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calc status regarding dispatch stock
|
||||
*
|
||||
* @param User $user
|
||||
* @return int <0 si ko, >0 si ok
|
||||
*/
|
||||
public function calcAndSetStatusDispatch(User $user) {
|
||||
global $conf;
|
||||
|
||||
if (! empty($conf->commande->enabled) && ! empty($conf->fournisseur->enabled) && ! empty($conf->global->WORKFLOW_SUPPLIER_ORDER_CLASSIFY_RECEIPT_ORDER))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +155,7 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$result = $commande->DispatchProduct($user, GETPOST($prod,'int'), GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger);
|
||||
$result = $commande->dispatchProduct($user, GETPOST($prod,'int'), GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger);
|
||||
if ($result < 0)
|
||||
{
|
||||
setEventMessages($commande->error, $commande->errors, 'errors');
|
||||
@ -213,10 +213,20 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error) {
|
||||
$result = $commande->calcAndSetStatusDispatch($user);
|
||||
if ($result < 0)
|
||||
{
|
||||
setEventMessages($commande->error, $commande->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $notrigger && ! $error)
|
||||
{
|
||||
global $conf, $langs, $user;
|
||||
// Call trigger
|
||||
|
||||
$result = $commande->call_trigger('ORDER_SUPPLIER_DISPATCH', $user);
|
||||
// End call triggers
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to bil
|
||||
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_SUPPLIER_ORDER_CLASSIFY_RECEIPT_ORDER=Classify supplier order status to Partially or Totally delivered on manual stock dispatch
|
||||
Loading…
Reference in New Issue
Block a user