NEW : massaction validate on supplier orders

This commit is contained in:
atm-gregr 2021-09-02 15:45:10 +02:00
parent cd09099409
commit 24117851cc
2 changed files with 250 additions and 185 deletions

View File

@ -87,7 +87,6 @@ $search_btn = GETPOST('button_search', 'alpha');
$search_remove_btn = GETPOST('button_removefilter', 'alpha'); $search_remove_btn = GETPOST('button_removefilter', 'alpha');
$status = GETPOST('statut', 'alpha'); $status = GETPOST('statut', 'alpha');
$search_status = GETPOST('search_status');
// Security check // Security check
$orderid = GETPOST('orderid', 'int'); $orderid = GETPOST('orderid', 'int');
@ -107,7 +106,7 @@ $pagenext = $page + 1;
if (!$sortfield) $sortfield = 'cf.ref'; if (!$sortfield) $sortfield = 'cf.ref';
if (!$sortorder) $sortorder = 'DESC'; if (!$sortorder) $sortorder = 'DESC';
if ($search_status == '') $search_status = -1; if ($search_status == '') $search_status = -5;
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new CommandeFournisseur($db); $object = new CommandeFournisseur($db);
@ -202,7 +201,7 @@ if (empty($reshook))
$search_total_vat = ''; $search_total_vat = '';
$search_total_ttc = ''; $search_total_ttc = '';
$search_project_ref = ''; $search_project_ref = '';
$search_status = -1; $search_status = '';
$search_orderyear = ''; $search_orderyear = '';
$search_ordermonth = ''; $search_ordermonth = '';
$search_orderday = ''; $search_orderday = '';
@ -225,8 +224,52 @@ if (empty($reshook))
$objectlabel = 'SupplierOrders'; $objectlabel = 'SupplierOrders';
$permissiontoread = $user->rights->fournisseur->commande->lire; $permissiontoread = $user->rights->fournisseur->commande->lire;
$permissiontodelete = $user->rights->fournisseur->commande->supprimer; $permissiontodelete = $user->rights->fournisseur->commande->supprimer;
$permissiontovalidate = $user->rights->fournisseur->commande->creer;
$uploaddir = $conf->fournisseur->commande->dir_output; $uploaddir = $conf->fournisseur->commande->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
if ($action == 'validate' && $permissiontovalidate)
{
if (GETPOST('confirm') == 'yes')
{
$objecttmp = new CommandeFournisseur($db);
$db->begin();
$error = 0;
foreach ($toselect as $checked)
{
if ($objecttmp->fetch($checked))
{
if ($objecttmp->statut == 0)
{
$objecttmp->date_commande = dol_now();
$result = $objecttmp->valid($user);
if ($result >= 0)
{
// If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
if (empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $user->rights->fournisseur->commande->approuver && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $objecttmp->hasProductsOrServices(1)))
{
$result = $objecttmp->approve($user);
setEventMessages($langs->trans("SupplierOrderValidatedAndApproved"), array($objecttmp->ref));
} else {
setEventMessages($langs->trans("SupplierOrderValidated"), array($objecttmp->ref));
}
}
else
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
}
}
}
}
if (!$error) $db->commit();
else $db->rollback();
}
}
// TODO Move this into mass action include // TODO Move this into mass action include
if ($massaction == 'confirm_createbills') if ($massaction == 'confirm_createbills')
@ -442,7 +485,7 @@ if (empty($reshook))
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$error++; $error++;
} }
}
} }
@ -514,6 +557,9 @@ if ($search_user > 0)
$sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
$sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
} }
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
$sql .= ' WHERE cf.fk_soc = s.rowid'; $sql .= ' WHERE cf.fk_soc = s.rowid';
$sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')'; $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
if ($socid > 0) $sql .= " AND s.rowid = ".$socid; if ($socid > 0) $sql .= " AND s.rowid = ".$socid;
@ -524,6 +570,7 @@ if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
if ($search_company) $sql .= natural_search('s.nom', $search_company); if ($search_company) $sql .= natural_search('s.nom', $search_company);
if ($search_request_author) $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author); if ($search_request_author) $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
if ($search_billed != '' && $search_billed >= 0) $sql .= " AND cf.billed = ".$db->escape($search_billed); if ($search_billed != '' && $search_billed >= 0) $sql .= " AND cf.billed = ".$db->escape($search_billed);
if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category; if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;
//Required triple check because statut=0 means draft filter //Required triple check because statut=0 means draft filter
if (GETPOST('statut', 'intcomma') !== '') if (GETPOST('statut', 'intcomma') !== '')
@ -628,6 +675,17 @@ if ($resql)
'builddoc'=>$langs->trans("PDFMerge"), 'builddoc'=>$langs->trans("PDFMerge"),
'presend'=>$langs->trans("SendByMail"), 'presend'=>$langs->trans("SendByMail"),
); );
if ($permissiontovalidate) {
if ($user->rights->fournisseur->commande->approuver && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE))
{
$arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
}
else
{
$arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
}
}
//if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer"); //if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
if ($user->rights->fournisseur->commande->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete"); if ($user->rights->fournisseur->commande->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array(); if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array();
@ -658,6 +716,10 @@ if ($resql)
$trackid = 'sord'.$object->id; $trackid = 'sord'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($massaction == 'prevalidate') {
print $form->formconfirm($_SERVER["PHP_SELF"].$fieldstosearchall, $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
}
if ($massaction == 'createbills') if ($massaction == 'createbills')
{ {
//var_dump($_REQUEST); //var_dump($_REQUEST);
@ -870,6 +932,7 @@ if ($resql)
$formorder->selectSupplierOrderStatus((strstr($search_status, ',') ?-1 : $search_status), 1, 'search_status'); $formorder->selectSupplierOrderStatus((strstr($search_status, ',') ?-1 : $search_status), 1, 'search_status');
print '</td>'; print '</td>';
} }
// Status billed // Status billed
if (!empty($arrayfields['cf.billed']['checked'])) if (!empty($arrayfields['cf.billed']['checked']))
{ {

View File

@ -120,6 +120,8 @@ SupplierOrderReceivedInDolibarr=Purchase Order %s received %s
SupplierOrderSubmitedInDolibarr=Purchase Order %s submitted SupplierOrderSubmitedInDolibarr=Purchase Order %s submitted
SupplierOrderClassifiedBilled=Purchase Order %s set billed SupplierOrderClassifiedBilled=Purchase Order %s set billed
OtherOrders=Other orders OtherOrders=Other orders
SupplierOrderValidatedAndApproved=Supplier order is validated and approved : %s
SupplierOrderValidated=Supplier order is validated : %s
##### Types de contacts ##### ##### Types de contacts #####
TypeContact_commande_internal_SALESREPFOLL=Representative following-up sales order TypeContact_commande_internal_SALESREPFOLL=Representative following-up sales order
TypeContact_commande_internal_SHIPPING=Representative following-up shipping TypeContact_commande_internal_SHIPPING=Representative following-up shipping