New : add a dashboard showing number of orders to bill #17963 (#18600)

* New : add a dashboard showing number of orders to bill #17963

* Fix orders statuses for dashboard and list

* Fix label in dashboard
This commit is contained in:
Maxime Kohlhaas 2023-07-31 02:36:10 +02:00 committed by GitHub
parent f6a5cc67c8
commit bcce9da09d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 20 deletions

View File

@ -3571,9 +3571,10 @@ class Commande extends CommonOrder
* Load indicators for dashboard (this->nbtodo and this->nbtodolate)
*
* @param User $user Object user
* @param String $mode Mode (toship, tobill, shippedtobill)
* @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK
*/
public function load_board($user)
public function load_board($user, $mode)
{
// phpcs:enable
global $conf, $langs;
@ -3589,18 +3590,48 @@ class Commande extends CommonOrder
}
$sql .= $clause." c.entity IN (".getEntity('commande').")";
//$sql.= " AND c.fk_statut IN (1,2,3) AND c.facture = 0";
$sql .= " AND ((c.fk_statut IN (".self::STATUS_VALIDATED.",".self::STATUS_SHIPMENTONPROCESS.")) OR (c.fk_statut = ".self::STATUS_CLOSED." AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
if ($mode == 'toship') {
// An order to ship is an open order (validated or in progress)
$sql .= " AND c.fk_statut IN (" . self::STATUS_VALIDATED . "," . self::STATUS_SHIPMENTONPROCESS . ")";
}
if ($mode == 'tobill') {
// An order to bill is an order not already billed
$sql .= " AND c.fk_statut IN (" . self::STATUS_VALIDATED . "," . self::STATUS_SHIPMENTONPROCESS . ", " . self::STATUS_CLOSED . ") AND c.facture = 0";
}
if ($mode == 'shippedtobill') {
// An order shipped and to bill is a delivered order not already billed
$sql .= " AND c.fk_statut IN (" . self::STATUS_CLOSED . ") AND c.facture = 0";
}
if ($user->socid) {
$sql .= " AND c.fk_soc = ".((int) $user->socid);
}
$resql = $this->db->query($sql);
if ($resql) {
$delay_warning = 0;
$label = $labelShort = $url = '';
if ($mode == 'toship') {
$delay_warning = $conf->commande->client->warning_delay / 60 / 60 / 24;
$url = DOL_URL_ROOT.'/commande/list.php?search_status=-2&mainmenu=commercial&leftmenu=orders';
$label = $langs->transnoentitiesnoconv("OrdersToProcess");
$labelShort = $langs->transnoentitiesnoconv("Opened");
}
if ($mode == 'tobill') {
$url = DOL_URL_ROOT.'/commande/list.php?search_status=-3&search_billed=0&mainmenu=commercial&leftmenu=orders';
$label = $langs->trans("OrdersToBill"); // We set here bill but may be billed or ordered
$labelShort = $langs->trans("ToBill");
}
if ($mode == 'shippedtobill') {
$url = DOL_URL_ROOT.'/commande/list.php?search_status=3&search_billed=0&mainmenu=commercial&leftmenu=orders';
$label = $langs->trans("OrdersToBill"); // We set here bill but may be billed or ordered
$labelShort = $langs->trans("StatusOrderDelivered").' '.$langs->trans("and").' '.$langs->trans("ToBill");
}
$response = new WorkboardResponse();
$response->warning_delay = $conf->commande->client->warning_delay / 60 / 60 / 24;
$response->label = $langs->trans("OrdersToProcess");
$response->labelShort = $langs->trans("Opened");
$response->url = DOL_URL_ROOT.'/commande/list.php?search_status=-3&mainmenu=commercial&leftmenu=orders';
$response->warning_delay = $delay_warning;
$response->label = $label;
$response->labelShort = $labelShort;
$response->url = $url;
$response->img = img_object('', "order");
$generic_commande = new Commande($this->db);
@ -3615,7 +3646,7 @@ class Commande extends CommonOrder
$generic_commande->date_livraison = $this->db->jdate($obj->delivery_date);
$generic_commande->delivery_date = $this->db->jdate($obj->delivery_date);
if ($generic_commande->hasDelay()) {
if ($mode == 'toship' && $generic_commande->hasDelay()) {
$response->nbtodolate++;
}
}

View File

@ -897,17 +897,12 @@ if ($search_status <> '') {
$sql .= ' AND c.fk_statut = '.((int) $search_status); // draft, validated, in process or canceled
}
}
if ($search_status == -2) { // "validated + in process"
//$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
$sql .= " AND (c.fk_statut IN (1,2))";
if ($search_status == -2) { // To shipp (validated and in progress)
$sql .= " AND c.fk_statut IN (1,2)";
}
if ($search_status == -3) { // "validated + in process + delivered"
//$sql.= ' AND c.fk_statut in (1,2,3)';
//$sql.= ' AND c.facture = 0'; // invoice not created
$sql .= ' AND (c.fk_statut IN (1,2,3))'; // validated, in process or closed
}
if ($search_status == -4) { // "validate + in progress"
$sql .= ' AND (c.fk_statut IN (1,2))'; // validated, in process
if ($search_status == -3) { // To bill (validated, in progress and shipped but not invoiced)
$sql .= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
}
}
@ -1741,9 +1736,9 @@ if ($resql) {
Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
-2=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
-3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
-2=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
);
print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);

View File

@ -209,7 +209,12 @@ if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) {
if (isModEnabled('commande') && empty($conf->global->MAIN_DISABLE_BLOCK_CUSTOMER) && $user->hasRight('commande', 'lire')) {
include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$board = new Commande($db);
$dashboardlines[$board->element] = $board->load_board($user);
// Number of customer orders to be shipped (validated and in progress)
$dashboardlines[$board->element.'_toship'] = $board->load_board($user, 'toship');
// Number of customer orders to be billed
$dashboardlines[$board->element.'_tobill'] = $board->load_board($user, 'tobill');
// Number of customer orders to be billed (delivered but not billed)
$dashboardlines[$board->element.'_shippedtobill'] = $board->load_board($user, 'shippedtobill');
}
// Number of suppliers orders a deal
@ -349,7 +354,7 @@ if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) {
'groupName' => 'Orders',
'globalStatsKey' => 'orders',
'stats' =>
array('commande'),
array('commande_toship', 'commande_tobill', 'commande_shippedtobill'),
),
'facture' =>
array(