diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e3b2c64c92a..c315a4fcd61 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -626,7 +626,7 @@ class Commande extends CommonOrder $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; - $sql .= " SET fk_statut = ".self::STATUS_DRAFT."',"; + $sql .= " SET fk_statut = ".self::STATUS_DRAFT.","; $sql .= " fk_user_modif = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 4b44959bc1a..15c45d6055b 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -6,7 +6,7 @@ * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2018-2021 Frédéric France * Copyright (C) 2019 Eric Seigne - * Copyright (C) 2021 Open-Dsi + * Copyright (C) 2021-2022 Open-Dsi * * 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,7 +47,7 @@ $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "produ $refresh = (GETPOSTISSET('submit') || GETPOSTISSET('vat_rate_show') || GETPOSTISSET('invoice_type')) ? true : false; $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : ''; -$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1; +$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'alphanohtml') : -1; include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php'; @@ -409,7 +409,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; @@ -643,7 +643,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 4c0ec1ff5a5..a6f09493a74 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -804,9 +804,6 @@ class ExtraFields if ($elementtype == 'order_supplier') { $elementtype = 'commande_fournisseur'; } - if ($elementtype == 'stock_mouvement') { - $elementtype = 'movement'; - } $array_name_label = array(); diff --git a/htdocs/core/lib/stock.lib.php b/htdocs/core/lib/stock.lib.php index 2e58e6c8082..066bf2165be 100644 --- a/htdocs/core/lib/stock.lib.php +++ b/htdocs/core/lib/stock.lib.php @@ -109,6 +109,11 @@ function stock_admin_prepare_head() $head[$h][2] = 'attributes'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/admin/stock_mouvement_extrafields.php'; + $head[$h][1] = $langs->trans("StockMouvementExtraFields"); + $head[$h][2] = 'stockMouvementAttributes'; + $h++; + complete_head_from_modules($conf, $langs, null, $head, $h, 'stock_admin', 'remove'); return $head; diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php index 40e50544b22..490b95cc92d 100644 --- a/htdocs/core/lib/tax.lib.php +++ b/htdocs/core/lib/tax.lib.php @@ -6,7 +6,7 @@ * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2015 Marcos García - * Copyright (C) 2021 Open-Dsi + * Copyright (C) 2021-2022 Open-Dsi * * 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 @@ -696,7 +696,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')) { // Count on delivery date (use invoice date as delivery is unknown) - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -739,7 +739,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " ORDER BY d.rowid, d.".$fk_facture; } else { // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -799,66 +799,71 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; - $list[$assoc['rate']]['datef'][] = $db->jdate($assoc['datef']); - $list[$assoc['rate']]['datep'][] = $db->jdate($assoc['datep']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = $assoc['dtype']; + $list[$rate_key]['datef'][] = $db->jdate($assoc['datef']); + $list[$rate_key]['datep'][] = $db->jdate($assoc['datep']); - $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; - $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; - $list[$assoc['rate']]['company_alias'][] = $assoc['company_alias']; - $list[$assoc['rate']]['company_email'][] = $assoc['company_email']; - $list[$assoc['rate']]['company_tva_intra'][] = $assoc['company_tva_intra']; - $list[$assoc['rate']]['company_client'][] = $assoc['company_client']; - $list[$assoc['rate']]['company_fournisseur'][] = $assoc['company_fournisseur']; - $list[$assoc['rate']]['company_customer_code'][] = $assoc['company_customer_code']; - $list[$assoc['rate']]['company_supplier_code'][] = $assoc['company_supplier_code']; - $list[$assoc['rate']]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; - $list[$assoc['rate']]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; - $list[$assoc['rate']]['company_status'][] = $assoc['company_status']; + $list[$rate_key]['company_name'][] = $assoc['company_name']; + $list[$rate_key]['company_id'][] = $assoc['company_id']; + $list[$rate_key]['company_alias'][] = $assoc['company_alias']; + $list[$rate_key]['company_email'][] = $assoc['company_email']; + $list[$rate_key]['company_tva_intra'][] = $assoc['company_tva_intra']; + $list[$rate_key]['company_client'][] = $assoc['company_client']; + $list[$rate_key]['company_fournisseur'][] = $assoc['company_fournisseur']; + $list[$rate_key]['company_customer_code'][] = $assoc['company_customer_code']; + $list[$rate_key]['company_supplier_code'][] = $assoc['company_supplier_code']; + $list[$rate_key]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; + $list[$rate_key]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; + $list[$rate_key]['company_status'][] = $assoc['company_status']; - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = $assoc['ptype']; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } @@ -876,7 +881,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice') || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice')) { // Count on invoice date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -919,7 +924,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql .= " ORDER BY d.rowid, d.".$fk_facture; } else { // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,"; $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, "; $sql .= " d.date_start as date_start, d.date_end as date_end,"; $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef,"; @@ -979,66 +984,71 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = $assoc['dtype']; - $list[$assoc['rate']]['datef'][] = $db->jdate($assoc['datef']); - $list[$assoc['rate']]['datep'][] = $db->jdate($assoc['datep']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = $assoc['dtype']; + $list[$rate_key]['datef'][] = $db->jdate($assoc['datef']); + $list[$rate_key]['datep'][] = $db->jdate($assoc['datep']); - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['company_name'][] = $assoc['company_name']; - $list[$assoc['rate']]['company_id'][] = $assoc['company_id']; - $list[$assoc['rate']]['company_alias'][] = $assoc['company_alias']; - $list[$assoc['rate']]['company_email'][] = $assoc['company_email']; - $list[$assoc['rate']]['company_tva_intra'][] = $assoc['company_tva_intra']; - $list[$assoc['rate']]['company_client'][] = $assoc['company_client']; - $list[$assoc['rate']]['company_fournisseur'][] = $assoc['company_fournisseur']; - $list[$assoc['rate']]['company_customer_code'][] = $assoc['company_customer_code']; - $list[$assoc['rate']]['company_supplier_code'][] = $assoc['company_supplier_code']; - $list[$assoc['rate']]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; - $list[$assoc['rate']]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; - $list[$assoc['rate']]['company_status'][] = $assoc['company_status']; + $list[$rate_key]['company_name'][] = $assoc['company_name']; + $list[$rate_key]['company_id'][] = $assoc['company_id']; + $list[$rate_key]['company_alias'][] = $assoc['company_alias']; + $list[$rate_key]['company_email'][] = $assoc['company_email']; + $list[$rate_key]['company_tva_intra'][] = $assoc['company_tva_intra']; + $list[$rate_key]['company_client'][] = $assoc['company_client']; + $list[$rate_key]['company_fournisseur'][] = $assoc['company_fournisseur']; + $list[$rate_key]['company_customer_code'][] = $assoc['company_customer_code']; + $list[$rate_key]['company_supplier_code'][] = $assoc['company_supplier_code']; + $list[$rate_key]['company_customer_accounting_code'][] = $assoc['company_customer_accounting_code']; + $list[$rate_key]['company_supplier_accounting_code'][] = $assoc['company_supplier_accounting_code']; + $list[$rate_key]['company_status'][] = $assoc['company_status']; - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = $assoc['ptype']; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = $assoc['ptype']; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } @@ -1056,7 +1066,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $sql = ''; // Count on payments date - $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; + $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.vat_src_code as vat_src_code, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,"; $sql .= " d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, "; $sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,"; $sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,"; @@ -1101,55 +1111,60 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire $rate = -1; $oldrowid = ''; while ($assoc = $db->fetch_array($resql)) { + $rate_key = $assoc['rate']; + if ($f_rate == 'tva_tx' && !empty($assoc['vat_src_code']) && !preg_match('/\(/', $rate_key)) { + $rate_key .= ' (' . $assoc['vat_src_code'] . ')'; + } + // Code to avoid warnings when array entry not defined - if (!isset($list[$assoc['rate']]['totalht'])) { - $list[$assoc['rate']]['totalht'] = 0; + if (!isset($list[$rate_key]['totalht'])) { + $list[$rate_key]['totalht'] = 0; } - if (!isset($list[$assoc['rate']]['vat'])) { - $list[$assoc['rate']]['vat'] = 0; + if (!isset($list[$rate_key]['vat'])) { + $list[$rate_key]['vat'] = 0; } - if (!isset($list[$assoc['rate']]['localtax1'])) { - $list[$assoc['rate']]['localtax1'] = 0; + if (!isset($list[$rate_key]['localtax1'])) { + $list[$rate_key]['localtax1'] = 0; } - if (!isset($list[$assoc['rate']]['localtax2'])) { - $list[$assoc['rate']]['localtax2'] = 0; + if (!isset($list[$rate_key]['localtax2'])) { + $list[$rate_key]['localtax2'] = 0; } if ($assoc['rowid'] != $oldrowid) { // Si rupture sur d.rowid $oldrowid = $assoc['rowid']; - $list[$assoc['rate']]['totalht'] += $assoc['total_ht']; - $list[$assoc['rate']]['vat'] += $assoc['total_vat']; - $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2']; + $list[$rate_key]['totalht'] += $assoc['total_ht']; + $list[$rate_key]['vat'] += $assoc['total_vat']; + $list[$rate_key]['localtax1'] += $assoc['total_localtax1']; + $list[$rate_key]['localtax2'] += $assoc['total_localtax2']; } - $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc']; - $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment'; - $list[$assoc['rate']]['datef'][] = $assoc['datef']; - $list[$assoc['rate']]['company_name'][] = ''; - $list[$assoc['rate']]['company_id'][] = ''; - $list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author']; - $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']); - $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']); + $list[$rate_key]['dtotal_ttc'][] = $assoc['total_ttc']; + $list[$rate_key]['dtype'][] = 'ExpenseReportPayment'; + $list[$rate_key]['datef'][] = $assoc['datef']; + $list[$rate_key]['company_name'][] = ''; + $list[$rate_key]['company_id'][] = ''; + $list[$rate_key]['user_id'][] = $assoc['fk_user_author']; + $list[$rate_key]['ddate_start'][] = $db->jdate($assoc['date_start']); + $list[$rate_key]['ddate_end'][] = $db->jdate($assoc['date_end']); - $list[$assoc['rate']]['facid'][] = $assoc['facid']; - $list[$assoc['rate']]['facnum'][] = $assoc['facnum']; - $list[$assoc['rate']]['type'][] = $assoc['type']; - $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc']; - $list[$assoc['rate']]['descr'][] = $assoc['descr']; + $list[$rate_key]['facid'][] = $assoc['facid']; + $list[$rate_key]['facnum'][] = $assoc['facnum']; + $list[$rate_key]['type'][] = $assoc['type']; + $list[$rate_key]['ftotal_ttc'][] = $assoc['ftotal_ttc']; + $list[$rate_key]['descr'][] = $assoc['descr']; - $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht']; - $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat']; - $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1']; - $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2']; + $list[$rate_key]['totalht_list'][] = $assoc['total_ht']; + $list[$rate_key]['vat_list'][] = $assoc['total_vat']; + $list[$rate_key]['localtax1_list'][] = $assoc['total_localtax1']; + $list[$rate_key]['localtax2_list'][] = $assoc['total_localtax2']; - $list[$assoc['rate']]['pid'][] = $assoc['pid']; - $list[$assoc['rate']]['pref'][] = $assoc['pref']; - $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment'; + $list[$rate_key]['pid'][] = $assoc['pid']; + $list[$rate_key]['pref'][] = $assoc['pref']; + $list[$rate_key]['ptype'][] = 'ExpenseReportPayment'; - $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id']; - $list[$assoc['rate']]['payment_ref'][] = $assoc['payment_ref']; - $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount']; + $list[$rate_key]['payment_id'][] = $assoc['payment_id']; + $list[$rate_key]['payment_ref'][] = $assoc['payment_ref']; + $list[$rate_key]['payment_amount'][] = $assoc['payment_amount']; $rate = $assoc['rate']; } diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 48292523326..9a903fdf4eb 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -87,3 +87,10 @@ INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) value INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('EXPENSE_REPORT_MODIFY','Expense report modified','Executed when an expense report is modified','expensereport',202); INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('HOLIDAY_MODIFY','Expense report modified','Executed when an expense report is modified','expensereport',212); + +CREATE TABLE llx_stock_mouvement_extrafields ( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + fk_object integer NOT NULL, + import_key varchar(14) +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_stock_mouvement_extrafields.sql b/htdocs/install/mysql/tables/llx_stock_mouvement_extrafields.sql new file mode 100644 index 00000000000..c13218b631e --- /dev/null +++ b/htdocs/install/mysql/tables/llx_stock_mouvement_extrafields.sql @@ -0,0 +1,24 @@ +-- =================================================================== +-- Copyright (C) 2022 Salvatore Chiariello +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + +CREATE TABLE llx_stock_mouvement_extrafields ( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + fk_object integer NOT NULL, + import_key varchar(14) +)ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index a8942bd337f..14715670882 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -410,3 +410,4 @@ DefaultBOMDesc=The default BOM recommended to use to manufacture this product. T Rank=Rank SwitchOnSaleStatus=Switch on sale status SwitchOnPurchaseStatus=Switch on purchase status +StockMouvementExtraFields= Extra Fields (stock mouvement) diff --git a/htdocs/langs/it_IT/products.lang b/htdocs/langs/it_IT/products.lang index f33ca8759bf..f5b9043b4e8 100644 --- a/htdocs/langs/it_IT/products.lang +++ b/htdocs/langs/it_IT/products.lang @@ -410,3 +410,4 @@ DefaultBOMDesc=The default BOM recommended to use to manufacture this product. T Rank=Rank SwitchOnSaleStatus=Switch on sale status SwitchOnPurchaseStatus=Switch on purchase status +StockMouvementExtraFields= Campi extra (movimenti scorte) diff --git a/htdocs/product/admin/stock_mouvement_extrafields.php b/htdocs/product/admin/stock_mouvement_extrafields.php new file mode 100644 index 00000000000..23e5aadc9cc --- /dev/null +++ b/htdocs/product/admin/stock_mouvement_extrafields.php @@ -0,0 +1,123 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2015 Jean-François Ferry + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/product/admin/stock_mouvement_extrafields.php + * \ingroup stock + * \brief Page to setup extra fields of stock mouvement + */ + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php"; +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; } +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php"; +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php"; +// Try main.inc.php using relative path +if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php"; +if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php"; +if (!$res) die("Include of main fails"); + +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/stock.lib.php'; + +// Load translation files required by the page +$langs->loadLangs(array('stock@stock', 'admin')); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val); + +$action = GETPOST('action', 'aZ09'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'stock_mouvement'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + + +llxHeader('', $langs->trans("StockSetup"), $help_url); + + +$linkback = ''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("StockSetup"), $linkback, 'title_setup'); + + +$head = stock_admin_prepare_head(); + +print dol_get_fiche_head($head, 'stockMouvementAttributes', $langs->trans("StockMouvementExtraFields"), -1, 'account'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +print dol_get_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') { + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* + * Creation of an optional field + */ +if ($action == 'create') { + print '
'; + print load_fiche_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* + * Edition of an optional field + */ +if ($action == 'edit' && !empty($attrname)) { + print "
"; + print load_fiche_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index da10faa4f34..3c080f159f8 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -655,11 +655,13 @@ class FormProduct } foreach ($productIdArray as $productId) { - foreach ($this->cache_lot[$productId] as $id => $arraytypes) { - if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) { - $label = $arraytypes['entrepot_label'].' - '; - $label .= $arraytypes['batch']; - $out .= ''; + if (array_key_exists($productId, $this->cache_lot)) { + foreach ($this->cache_lot[$productId] as $id => $arraytypes) { + if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) { + $label = $arraytypes['entrepot_label'] . ' - '; + $label .= $arraytypes['batch']; + $out .= ''; + } } } } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 27b2bdaff2c..98cff66bf1f 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5120,9 +5120,10 @@ class Product extends CommonObject * @param string $origin_element Origin element type * @param int $origin_id Origin id of element * @param int $disablestockchangeforsubproduct Disable stock change for sub-products of kit (usefull only if product is a subproduct) - * @return int <0 if KO, >0 if OK + * @param array $extrafields Array of extrafields + * @return int <0 if KO, >0 if OK */ - public function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label = '', $price = 0, $inventorycode = '', $origin_element = '', $origin_id = null, $disablestockchangeforsubproduct = 0) + public function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label = '', $price = 0, $inventorycode = '', $origin_element = '', $origin_id = null, $disablestockchangeforsubproduct = 0, $extrafields = null) { // phpcs:enable if ($id_entrepot) { @@ -5145,6 +5146,11 @@ class Product extends CommonObject $result = $movementstock->_create($user, $this->id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode, '', '', '', '', false, 0, $disablestockchangeforsubproduct); if ($result >= 0) { + if ($extrafields) { + $array_options = $extrafields->getOptionalsFromPost('stock_mouvement'); + $movementstock->array_options = $array_options; + $movementstock->insertExtraFields(); + } $this->db->commit(); return 1; } else { @@ -5174,9 +5180,10 @@ class Product extends CommonObject * @param string $origin_element Origin element type * @param int $origin_id Origin id of element * @param int $disablestockchangeforsubproduct Disable stock change for sub-products of kit (usefull only if product is a subproduct) + * @param array $extrafields Array of extrafields * @return int <0 if KO, >0 if OK */ - public function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label = '', $price = 0, $dlc = '', $dluo = '', $lot = '', $inventorycode = '', $origin_element = '', $origin_id = null, $disablestockchangeforsubproduct = 0) + public function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label = '', $price = 0, $dlc = '', $dluo = '', $lot = '', $inventorycode = '', $origin_element = '', $origin_id = null, $disablestockchangeforsubproduct = 0, $extrafields = null) { // phpcs:enable if ($id_entrepot) { @@ -5199,6 +5206,11 @@ class Product extends CommonObject $result = $movementstock->_create($user, $this->id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode, '', $dlc, $dluo, $lot, false, 0, $disablestockchangeforsubproduct); if ($result >= 0) { + if ($extrafields) { + $array_options = $extrafields->getOptionalsFromPost('stock_mouvement'); + $movementstock->array_options = $array_options; + $movementstock->insertExtraFields(); + } $this->db->commit(); return 1; } else { diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index 405528a3480..73c6751262a 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -139,6 +139,9 @@ $arrayfields = array( //'m.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), //'m.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500) ); + +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; + if (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) { unset($arrayfields['pl.sellby']); } @@ -381,7 +384,9 @@ if ($action == "correct_stock") { $batch, GETPOST('inventorycode', 'alphanohtml'), $origin_element, - $origin_id + $origin_id, + 0, + $extrafields ); // We do not change value of stock for a correction } else { $result = $product->correct_stock( @@ -393,7 +398,9 @@ if ($action == "correct_stock") { price2num(GETPOST('unitprice'), 'MT'), GETPOST('inventorycode', 'alphanohtml'), $origin_element, - $origin_id + $origin_id, + 0, + $extrafields ); // We do not change value of stock for a correction } @@ -500,7 +507,11 @@ if ($action == "transfert_stock" && !$cancel) { $eatby, $sellby, $batch, - GETPOST('inventorycode') + GETPOST('inventorycode'), + '', + null, + 0, + $extrafields ); // Add stock $result2 = $product->correct_stock_batch( @@ -513,7 +524,11 @@ if ($action == "transfert_stock" && !$cancel) { $eatby, $sellby, $batch, - GETPOST('inventorycode', 'alphanohtml') + GETPOST('inventorycode', 'alphanohtml'), + '', + null, + 0, + $extrafields ); } } else { @@ -525,7 +540,11 @@ if ($action == "transfert_stock" && !$cancel) { 1, GETPOST("label", 'san_alpha'), $pricesrc, - GETPOST('inventorycode', 'alphanohtml') + GETPOST('inventorycode', 'alphanohtml'), + '', + null, + 0, + $extrafields ); // Add stock @@ -536,7 +555,11 @@ if ($action == "transfert_stock" && !$cancel) { 0, GETPOST("label", 'san_alpha'), $pricedest, - GETPOST('inventorycode', 'alphanohtml') + GETPOST('inventorycode', 'alphanohtml'), + '', + null, + 0, + $extrafields ); } if (!$error && $result1 >= 0 && $result2 >= 0) { @@ -1434,6 +1457,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) { } // Extra fields + $object = $movement; include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); diff --git a/htdocs/product/stock/tpl/extrafields_add.tpl.php b/htdocs/product/stock/tpl/extrafields_add.tpl.php new file mode 100644 index 00000000000..62921f0a6e0 --- /dev/null +++ b/htdocs/product/stock/tpl/extrafields_add.tpl.php @@ -0,0 +1,51 @@ + + * Copyright (C) 2014 Juanjo Menent + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Need to have following variables defined: + * $object (invoice, order, ...) + * $action + * $conf + * $langs + * + * $parameters + * $cols + */ + +// Protection to avoid direct call of template +if (empty($conf) || !is_object($conf)) { + print "Error, template page can't be called as URL"; + exit; +} + +?> + +executeHooks('formObjectOptions', $parameters, $movement, $action); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; +if (empty($reshook)) { + $params = array(); + if (isset($tpl_context)) $params['tpl_context'] = $tpl_context; + $params['cols'] = $parameters['colspanvalue']; + print $movement->showOptionals($extrafields, 'create', $params); +} + +?> + diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 00699b95e18..eb84df7d14e 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -179,6 +179,9 @@ print '