From fb49c64454428fb51bd437e792849e1861409a75 Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 12 Oct 2024 16:20:43 +0200 Subject: [PATCH] Fix commande/list & facture-rec.class --- dev/tools/phan/baseline.txt | 4 +- htdocs/categories/class/categorie.class.php | 4 +- htdocs/commande/list.php | 28 ++- htdocs/compta/facture/card-rec.php | 6 +- .../facture/class/facture-rec.class.php | 160 +++++++++++++----- htdocs/core/class/html.form.class.php | 4 +- 6 files changed, 151 insertions(+), 55 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 22aa739058b0b..3515ca8189a78 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -130,7 +130,7 @@ return [ 'htdocs/commande/class/commande.class.php' => ['PhanUndeclaredProperty'], 'htdocs/commande/class/commandestats.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], 'htdocs/commande/customer.php' => ['PhanUndeclaredGlobalVariable'], - 'htdocs/commande/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], + 'htdocs/commande/list.php' => ['PhanUndeclaredProperty'], 'htdocs/commande/list_det.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/commande/stats/index.php' => ['PhanPossiblyUndeclaredGlobalVariable'], 'htdocs/commande/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], @@ -162,7 +162,7 @@ return [ 'htdocs/compta/facture/card-rec.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/card.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/facture/class/api_invoices.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeComparisonFromArray', 'PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], + 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/facture/class/facture.class.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/facture/class/facturestats.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType'], 'htdocs/compta/facture/class/paymentterm.class.php' => ['PhanPluginUnknownPropertyType'], diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 6e5e8c5004c52..035736b0e038e 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1171,12 +1171,12 @@ protected function load_motherof() * fullpath = Full path built with the id's * * @param string $type Type of categories ('customer', 'supplier', 'contact', 'product', 'member', ...) - * @param int|string|array $fromid Keep only or Exclude (depending on $include parameter) all categories (including the leaf $fromid) into the tree after this id $fromid. + * @param int|string|int[] $fromid Keep only or Exclude (depending on $include parameter) all categories (including the leaf $fromid) into the tree after this id $fromid. * $fromid can be an : * - int (id of category) * - string (categories ids separated by comma) * - array (list of categories ids) - * @param int $include [=0] Removed or 1=Keep only + * @param int<0,1> $include [=0] Removed or 1=Keep only * @return int<-1,-1>|array Array of categories. this->cats and this->motherof are set, -1 on error */ public function get_full_arbo($type, $fromid = 0, $include = 0) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 747c5512e6637..aa3e59882ff84 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -70,6 +70,8 @@ if (getDolGlobalInt('MAIN_SEE_SUBORDINATES')) { $userschilds = $user->getAllChildIds(); +} else { + $userschilds = array(); } // Search Parameters @@ -131,6 +133,12 @@ if ($search_option == 'late') { $search_status = '-2'; } +$search_orderday = ''; +$search_ordermonth = ''; +$search_orderyear = ''; +$search_deliveryday = ''; +$search_deliverymonth = ''; +$search_deliveryyear = ''; $diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id; @@ -249,6 +257,12 @@ } $permissiontoreadallthirdparty = $user->hasRight('societe', 'client', 'voir'); +$permissiontoread = false; +$permissiontovalidate = false; +$permissiontoclose = false; +$permissiontocancel = false; +$permissiontosendbymail = false; +$objectclass = null; $result = restrictedArea($user, 'commande', $id, ''); @@ -447,6 +461,7 @@ $fk_parent_line = 0; $num = count($lines); + $array_options = array(); for ($i = 0; $i < $num; $i++) { $desc = ($lines[$i]->desc ? $lines[$i]->desc : ''); @@ -732,7 +747,7 @@ } } } -if ($action == 'validate' && $permissiontoadd) { +if ($action == 'validate' && $permissiontoadd && $objectclass !== null) { if (GETPOST('confirm') == 'yes') { $objecttmp = new $objectclass($db); $db->begin(); @@ -768,7 +783,7 @@ } } } -if ($action == 'shipped' && $permissiontoadd) { +if ($action == 'shipped' && $permissiontoadd && $objectclass !== null) { if (GETPOST('confirm') == 'yes') { $objecttmp = new $objectclass($db); $db->begin(); @@ -801,7 +816,7 @@ } // Closed records -if (!$error && $massaction === 'setbilled' && $permissiontoclose) { +if (!$error && $massaction === 'setbilled' && $permissiontoclose && $objectclass !== null) { $db->begin(); $objecttmp = new $objectclass($db); @@ -1535,7 +1550,7 @@ include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; $tmptitle = $langs->trans('IncludingProductWithTag'); - $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, array(), 1); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1); $moreforfilter .= '
'; } @@ -2435,7 +2450,7 @@ // Channel if (!empty($arrayfields['c.fk_input_reason']['checked'])) { print ''; - $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', ''); + $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', 0); print ''; if (!$i) { $totalarray['nbfield']++; @@ -2710,6 +2725,7 @@ if (!empty($arrayfields['shippable']['checked'])) { print ''; if (!empty($show_shippable_command) && isModEnabled('stock')) { + $text_icon = ''; if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) { $generic_commande->getLinesArray(); // Load array ->lines $generic_commande->loadExpeditions(); // Load array ->expeditions @@ -2757,6 +2773,7 @@ $generic_product->load_stats_commande(0, '1,2'); $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty']; } else { + // @phan-suppress-next-line PhanTypeInvalidDimOffset $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer']; } $stock_order = $generic_product->stats_commande['qty']; @@ -2766,6 +2783,7 @@ $generic_product->load_stats_commande_fournisseur(0, '3'); $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty']; } else { + // @phan-suppress-next-line PhanTypeInvalidDimOffset $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier']; } $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty']; diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 9bd0bc7f0acc0..557cadbff6e3f 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -691,7 +691,7 @@ setEventMessages($mesg, null, 'errors'); } else { // Insert line - $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, -1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice, $fk_parent_line); + $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, 0, $pu_ttc, $type, -1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice, $fk_parent_line); if ($result > 0) { // Define output language and generate document @@ -985,6 +985,8 @@ $formother = new FormOther($db); if (isModEnabled('project')) { $formproject = new FormProjets($db); +} else { + $formproject = null; } $companystatic = new Societe($db); $invoicerectmp = new FactureRec($db); @@ -1101,7 +1103,7 @@ print $object->showOptionals($extrafields, 'create', $parameters); // Project - if (isModEnabled('project') && is_object($object->thirdparty) && $object->thirdparty->id > 0) { + if (isModEnabled('project') && is_object($object->thirdparty) && $object->thirdparty->id > 0 && is_object($formproject)) { $projectid = GETPOST('projectid') ? GETPOST('projectid') : $object->fk_project; $langs->load('projects'); print ''.$langs->trans('Project').''; diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index eb1a682dc207f..eb8cb1d7180f4 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -91,33 +91,59 @@ class FactureRec extends CommonInvoice public $titre; /** - * @var double + * @var float */ public $multicurrency_subprice; + /** + * @var int + */ public $socid; + /** + * @var int + */ public $number; + /** + * @var int + */ public $date; //public $remise; //public $remise_absolue; //public $remise_percent; /** - * @deprecated + * @deprecated Use $total_ht * @see $total_ht + * @var float */ public $total; /** - * @deprecated + * @deprecated Use $total_tva * @see $total_tva + * @var float */ public $tva; + /** + * @var int|string + */ public $date_last_gen; + /** + * @var int|string|null + */ public $date_when; + /** + * @var int + */ public $nb_gen_done; + /** + * @var int + */ public $nb_gen_max; + /** + * @var User + */ public $user_author; /** @@ -130,6 +156,9 @@ class FactureRec extends CommonInvoice */ public $unit_frequency; + /** + * @var int + */ public $rang; /** @@ -137,18 +166,36 @@ class FactureRec extends CommonInvoice */ public $special_code; + /** + * @var int<0,1> + */ public $usenewprice = 0; /** * @var int Deadline for payment */ public $date_lim_reglement; + /** + * @var string + */ public $cond_reglement_code; // Code in llx_c_paiement + /** + * @var string + */ public $mode_reglement_code; // Code in llx_c_paiement + /** + * @var int + */ public $suspended; // status + /** + * @var int<0,1> + */ public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice + /** + * @var int<0,1> + */ public $generate_pdf; // 1 to generate PDF on invoice generation (default) @@ -241,11 +288,11 @@ public function __construct(DoliDB $db) /** * Create a predefined invoice * - * @param User $user User object - * @param int $facid Id of source invoice - * @param int $notrigger No trigger - * @param array $onlylines Only the lines of the array - * @return int Return integer <0 if KO, id of invoice created if OK + * @param User $user User object + * @param int $facid Id of source invoice + * @param int<0,1> $notrigger No trigger + * @param int[] $onlylines Only the lines of the array + * @return int Return integer <0 if KO, id of invoice created if OK */ public function create($user, $facid, $notrigger = 0, $onlylines = array()) { @@ -355,51 +402,53 @@ public function create($user, $facid, $notrigger = 0, $onlylines = array()) $num = count($facsrc->lines); for ($i = 0; $i < $num; $i++) { - if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) { + $facline = $facsrc->lines[$i]; + '@phan-var-force FactureLigneRec $facline'; + if (!empty($onlylines) && !in_array($facline->id, $onlylines)) { continue; // Skip unselected lines } // Reset fk_parent_line for no child products and special product - if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) { + if (($facline->product_type != 9 && empty($facline->fk_parent_line)) || $facline->product_type == 9) { $fk_parent_line = 0; } - $tva_tx = $facsrc->lines[$i]->tva_tx; - if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\(/', (string) $tva_tx)) { - $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')'; + $tva_tx = $facline->tva_tx; + if (!empty($facline->vat_src_code) && !preg_match('/\(/', (string) $tva_tx)) { + $tva_tx .= ' ('.$facline->vat_src_code.')'; } $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START'); $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END'); $result_insert = $this->addline( - $facsrc->lines[$i]->desc, - $facsrc->lines[$i]->subprice, - $facsrc->lines[$i]->qty, + $facline->desc, + $facline->subprice, + $facline->qty, $tva_tx, - $facsrc->lines[$i]->localtax1_tx, - $facsrc->lines[$i]->localtax2_tx, - $facsrc->lines[$i]->fk_product, - $facsrc->lines[$i]->remise_percent, + $facline->localtax1_tx, + $facline->localtax2_tx, + $facline->fk_product, + $facline->remise_percent, 'HT', - $facsrc->lines[$i]->info_bits, - '', + $facline->info_bits, + 0, 0, - $facsrc->lines[$i]->product_type, - $facsrc->lines[$i]->rang, - $facsrc->lines[$i]->special_code, - $facsrc->lines[$i]->label, - $facsrc->lines[$i]->fk_unit, - $facsrc->lines[$i]->multicurrency_subprice, + $facline->product_type, + $facline->rang, + $facline->special_code, + $facline->label, + $facline->fk_unit, + $facline->multicurrency_subprice, $default_start_fill, $default_end_fill, - null, - $facsrc->lines[$i]->pa_ht, + 0, + $facline->pa_ht, $fk_parent_line ); // Defined the new fk_parent_line - if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) { + if ($result_insert > 0 && $facline->product_type == 9) { $fk_parent_line = $result_insert; } @@ -411,9 +460,9 @@ public function create($user, $facid, $notrigger = 0, $onlylines = array()) $result2 = $objectline->fetch($result_insert); if ($result2 > 0) { // Extrafields - if (method_exists($facsrc->lines[$i], 'fetch_optionals')) { - $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id); - $objectline->array_options = $facsrc->lines[$i]->array_options; + if (method_exists($facline, 'fetch_optionals')) { + $facline->fetch_optionals($facline->id); + $objectline->array_options = $facline->array_options; } $result = $objectline->insertExtraFields(); @@ -1921,9 +1970,9 @@ public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0) /** * Update the next date of execution * - * @param datetime $date date of execution - * @param int $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done - * @param int $notrigger Disable the trigger + * @param int $date date of execution + * @param int<0,max> $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done + * @param int<0,1> $notrigger Disable the trigger * @return int Return integer <0 if KO, >0 if OK */ public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0) @@ -2155,23 +2204,50 @@ class FactureLigneRec extends CommonInvoiceLine */ public $fk_parent_attribute = 'fk_facture'; - //! From llx_facturedet_rec - //! Id facture + //!From llx_facturedet_rec + /** + * @var int Id facture + */ public $fk_facture; - //! Id parent line + /** + * @var int Id parent line + */ public $fk_parent_line; + /** + * @var int + */ public $fk_product_fournisseur_price; - public $fk_fournprice; // For backward compatibility + /** + * @var int + * @deprecated For backward compatibility + */ + public $fk_fournprice; + /** + * @var int + */ public $rang; //public $situation_percent; // Not supported on recurring invoice line + /** + * @var string + */ public $desc; + /** + * @var string + */ public $description; - public $fk_product_type; // Use instead product_type + /** + * @var int + * @deprecated Use product_type / $product->type + */ + public $fk_product_type; + /** + * @var int + */ public $fk_contract_line; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 79fc124845a88..5a55e7067efbc 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5316,7 +5316,7 @@ public function formSelectAccount($page, $selected = '', $htmlname = 'fk_account * @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element). Not used if $outputmode = 1. * @param string $htmlname HTML field name * @param int $maxlength Maximum length for labels - * @param int|string|array $fromid Keep only or Exclude (depending on $include parameter) all categories (including the leaf $fromid) into the tree after this id $fromid. + * @param int|string|int[] $fromid Keep only or Exclude (depending on $include parameter) all categories (including the leaf $fromid) into the tree after this id $fromid. * $fromid can be an : * - int (id of category) * - string (categories ids separated by comma) @@ -5324,7 +5324,7 @@ public function formSelectAccount($page, $selected = '', $htmlname = 'fk_account * @param int<0,3> $outputmode 0=HTML select string, 1=Array with full label only, 2=Array extended, 3=Array with full picto + label * @param int<0,1> $include [=0] Removed or 1=Keep only * @param string $morecss More CSS - * @param int<0,2> $useempty 0=No empty value, 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. Default is 1. + * @param int<0,2> $useempty 0=No empty value, 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. Default is 1. * @return string|array|array|array String list or Array of categories * @see select_categories() */