From 7d1b409e59d58e25209f8baa5ca1477a059d2803 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Mon, 15 Nov 2021 14:35:55 +0100 Subject: [PATCH] NEW : accountancy massaction preselect account (productaccount page) --- htdocs/accountancy/admin/productaccount.php | 46 ++++++++++++++++----- htdocs/langs/en_US/compta.lang | 4 +- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index e7616ededf3..a77f049e25f 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -4,6 +4,7 @@ * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) + * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,9 +48,12 @@ if (empty($user->rights->accounting->bind->write)) { // search & action GETPOST $action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); $codeventil_buy = GETPOST('codeventil_buy', 'array'); $codeventil_sell = GETPOST('codeventil_sell', 'array'); $chk_prod = GETPOST('chk_prod', 'array'); +$default_account = GETPOST('default_account', 'int'); +$confirm = GETPOST('confirm', 'alpha'); $account_number_buy = GETPOST('account_number_buy'); $account_number_sell = GETPOST('account_number_sell'); $changeaccount = GETPOST('changeaccount', 'array'); @@ -68,7 +72,6 @@ $search_onsell = GETPOST('search_onsell', 'alpha'); $search_onpurchase = GETPOST('search_onpurchase', 'alpha'); $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha'); -$btn_changeaccount = GETPOST('changeaccount', 'alpha'); $btn_changetype = GETPOST('changetype', 'alpha'); $optioncss = GETPOST('optioncss', 'alpha'); @@ -165,7 +168,7 @@ if ($action == 'update') { } } - if (!empty($btn_changeaccount)) { + if (!empty($chk_prod) && $massaction === 'changeaccount') { //$msg = '
' . $langs->trans("Processing") . '...
'; if (!empty($chk_prod) && in_array($accounting_product_mode, $accounting_product_modes)) { $accounting = new AccountingAccount($db); @@ -436,11 +439,27 @@ if ($result) { $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + if ($massaction !== 'set_default_account') { + $arrayofmassactions = array( + 'changeaccount'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Save") + ,'set_default_account'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount") + ); + $massactionbutton = $form->selectMassAction('', $arrayofmassactions, 1); + } + $buttonsave = ''; //print '
'.$buttonsave.'
'; $texte = $langs->trans("ListOfProductsServices"); - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $buttonsave, $num, $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1); + + if ($massaction == 'set_default_account') { + $formquestion[]=array('type' => 'other', + 'name' => 'set_default_account', + 'label' => $langs->trans("AccountancyCode"), + 'value' => $form->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone')); + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($chk_prod)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1); + } print '
'; print ''; @@ -645,7 +664,7 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') { // Accounting account buy intra (In EEC) @@ -659,7 +678,7 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') { // Accounting account buy export (Out of EEC) @@ -673,7 +692,7 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') { // Accounting account sell @@ -687,7 +706,7 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') { // Accounting account sell intra (In EEC) @@ -701,7 +720,7 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } else { // Accounting account sell export (Out of EEC) @@ -714,13 +733,20 @@ if ($result) { if (!empty($obj->aaid)) { $defaultvalue = ''; // Do not suggest default new value is code is already valid } - print $form->select_account($defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); + print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect'); print ''; } + if (!empty($chk_prod)) { + $ischecked = 0; + if (in_array($product_static->id, $chk_prod)) { + $ischecked=true; + } + } + // Checkbox select print ''; + print ''; print ""; $i++; } diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index ace3e518003..0a17b937b1f 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -294,4 +294,6 @@ InvoiceNotLate15Days = To be collected (15 to 30 days) InvoiceNotLate30Days = To be collected (> 30 days) InvoiceToPay=To pay (< 15 days) InvoiceToPay15Days=To pay (15 to 30 days) -InvoiceToPay30Days=To pay (> 30 days) \ No newline at end of file +InvoiceToPay30Days=To pay (> 30 days) +ConfirmPreselectAccount=Preselect accountancy code +ConfirmPreselectAccountQuestion=Are you sure you want to preselect the %s selected lines with this accountancy code ?
'; - print '