diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index 55700fe8439..1e7c38b2607 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -369,9 +369,9 @@ if ($result) { print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); print ''.$langs->trans("DescVentilDoneCustomer").'
'; - print '
'.$langs->trans("ChangeAccount").'
'; + print '
'.$langs->trans("ChangeAccount").' '; print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle'); - print '
'; + print '
'; $moreforfilter = ''; diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php index da8bc0cd5e9..61e17ab669c 100644 --- a/htdocs/accountancy/supplier/lines.php +++ b/htdocs/accountancy/supplier/lines.php @@ -369,9 +369,9 @@ if ($result) { print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); print ''.$langs->trans("DescVentilDoneSupplier").'
'; - print '
'.$langs->trans("ChangeAccount").'
'; + print '
'.$langs->trans("ChangeAccount").' '; print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle'); - print '
'; + print '
'; $moreforfilter = ''; diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index ca1ad342d8a..dfc035bf1aa 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -1839,7 +1839,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; } - // Login Dolibarr + // Login Dolibarr - Link to user print ''; $editenable = $user->rights->adherent->creer && $user->rights->user->user->creer; print $form->editfieldkey('LinkedToDolibarrUser', 'login', '', $object, $editenable); diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index f7a8060d9a5..fcf65a5b668 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -623,7 +623,7 @@ if ($rowid > 0) { print ''; } - // Login Dolibarr + // Login Dolibarr - Link to user print ''; print ''; - print ''; + print ''; print ''; // Multicurrency Amount VAT print ''; - print ''; + print ''; print ''; // Multicurrency Amount TTC print ''; - print ''; + print ''; print ''; } @@ -2378,23 +2380,23 @@ if ($action == 'create' && $usercancreate) { $alert = ' '.img_warning($langs->trans('OrderMinAmount').': '.price($object->thirdparty->order_min_amount)); } print ''; - print ''; + print ''; // Total VAT - print ''; + print ''; // Amount Local Taxes if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1 print ''; - print ''; + print ''; } if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2 IRPF print ''; - print ''; + print ''; } // Total TTC - print ''; + print ''; // Statut //print ''; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5186bbb297c..22cd946275c 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2267,7 +2267,6 @@ class Facture extends CommonInvoice $sql .= ' SET fk_facture = NULL, fk_facture_line = NULL'; $sql .= ' WHERE fk_facture_line IN ('.$this->db->sanitize(join(',', $list_rowid_det)).')'; - dol_syslog(get_class($this)."::delete", LOG_DEBUG); if (!$this->db->query($sql)) { $this->error = $this->db->error()." sql=".$sql; $this->errors[] = $this->error; @@ -2276,6 +2275,30 @@ class Facture extends CommonInvoice } } + // Remove other links to the deleted invoice + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'eventorganization_conferenceorboothattendee'; + $sql .= ' SET fk_invoice = NULL'; + $sql .= ' WHERE fk_invoice = '.((int) $rowid); + + if (!$this->db->query($sql)) { + $this->error = $this->db->error()." sql=".$sql; + $this->errors[] = $this->error; + $this->db->rollback(); + return -5; + } + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'projet_task_time'; + $sql .= ' SET invoice_id = NULL, invoice_line_id = NULL'; + $sql .= ' WHERE invoice_id = '.((int) $rowid); + + if (!$this->db->query($sql)) { + $this->error = $this->db->error()." sql=".$sql; + $this->errors[] = $this->error; + $this->db->rollback(); + return -5; + } + // If we decrease stock on invoice validation, we increase back if a warehouse id was provided if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse != -1) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; @@ -2299,17 +2322,13 @@ class Facture extends CommonInvoice // Invoice line extrafileds $main = MAIN_DB_PREFIX.'facturedet'; $ef = $main."_extrafields"; - $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")"; + $sqlef = "DELETE FROM ".$ef." WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")"; // Delete invoice line $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.((int) $rowid); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if ($this->db->query($sqlef) && $this->db->query($sql) && $this->delete_linked_contact()) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.((int) $rowid); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); if ($resql) { // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php index ca4d3d6ccaf..5fe028e1268 100644 --- a/htdocs/compta/facture/stats/index.php +++ b/htdocs/compta/facture/stats/index.php @@ -42,7 +42,7 @@ $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); // Load translation files required by the page $langs->loadLangs(array('bills', 'companies', 'other')); -$mode = GETPOST("mode") ?GETPOST("mode") : 'customer'; +$mode = GETPOST("mode") ? GETPOST("mode") : 'customer'; if ($mode == 'customer' && !$user->rights->facture->lire) { accessforbidden(); } @@ -244,7 +244,7 @@ if (!count($arrayyears)) { $h = 0; $head = array(); -$head[$h][0] = DOL_URL_ROOT.'/compta/facture/stats/index.php?mode='.$mode; +$head[$h][0] = DOL_URL_ROOT.'/compta/facture/stats/index.php?mode='.urlencode($mode); $head[$h][1] = $langs->trans("ByMonthYear"); $head[$h][2] = 'byyear'; $h++; @@ -261,12 +261,12 @@ complete_head_from_modules($conf, $langs, null, $head, $h, $type); print dol_get_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1); // We use select_thirdparty_list instead of select_company so we can use $filter and share same code for customer and supplier. -$tmp_companies = $form->select_thirdparty_list($socid, 'socid', $filter, 1, 0, 0, array(), '', 1); -//Array passed as an argument to Form::selectarray to build a proper select input -$companies = array(); - -foreach ($tmp_companies as $value) { - $companies[$value['key']] = $value['label']; +$filter = ''; +if ($mode == 'customer') { + $filter = 's.client in (1,2,3)'; +} +if ($mode == 'supplier') { + $filter = 's.fournisseur = 1'; } print '
'; @@ -281,14 +281,8 @@ print '
'; print $langs->trans("LinkedToDolibarrUser"); @@ -641,7 +641,9 @@ if ($rowid > 0) { $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', ''); } else { if ($object->user_id) { - $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none'); + $linkeduser = new User($db); + $linkeduser->fetch($object->user_id); + print $linkeduser->getNomUrl(-1); } else { print ''.$langs->trans("NoDolibarrAccess").''; } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 2e37cdcd0a1..e1896cc48b6 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -294,6 +294,7 @@ if (empty($reshook)) { if (!empty($origin) && !empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; + $regs = array(); if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { $element = $regs [1]; $subelement = $regs [2]; @@ -1410,6 +1411,7 @@ if (empty($reshook)) { /* * View */ + $title = $langs->trans('Order')." - ".$langs->trans('Card'); $help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge'; llxHeader('', $title, $help_url); @@ -2358,17 +2360,17 @@ if ($action == 'create' && $usercancreate) { if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print '
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).''.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).''.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).''.price($object->multicurrency_total_ttc, '', $langs, 0, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$langs->trans('AmountHT').''.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).$alert.''.price($object->total_ht, 1, '', 1, -1, -1, $conf->currency).$alert.'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'.price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency).'
' . $langs->trans('Status') . '' . $object->getLibStatut(4) . '
'; print ''; // Company print ''; // ThirdParty Type diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 835e7f0cafb..44ace66f05b 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -1288,7 +1288,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { if ($objsoc->id > 0) { $morehtmlref .= $objsoc->getNomUrl(1, 'contact'); } else { - $morehtmlref .= $langs->trans("ContactNotLinkedToCompany"); + $morehtmlref .= ''.$langs->trans("ContactNotLinkedToCompany").''; } } $morehtmlref .= ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index eb5edb921f3..7adf7a89079 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3539,7 +3539,7 @@ abstract class CommonObject $this->db->free($resql); - // Now update global field total_ht, total_ttc and tva + // Now update global field total_ht, total_ttc, total_tva, total_localtax1, total_localtax2, multicurrency_total_* $fieldht = 'total_ht'; $fieldtva = 'tva'; $fieldlocaltax1 = 'localtax1'; @@ -3582,6 +3582,7 @@ abstract class CommonObject dol_syslog(get_class($this)."::update_price", LOG_DEBUG); $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->error = $this->db->lasterror(); diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 1400dc40458..381699f216b 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -126,7 +126,7 @@ function project_prepare_head(Project $project, $moreparam = '') if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) || !empty($conf->propal->enabled) || !empty($conf->commande->enabled) || !empty($conf->facture->enabled) || !empty($conf->contrat->enabled) - || !empty($conf->ficheinter->enabled) || !empty($conf->agenda->enabled) || !empty($conf->deplacement->enabled)) { + || !empty($conf->ficheinter->enabled) || !empty($conf->agenda->enabled) || !empty($conf->deplacement->enabled) || !empty($conf->stock->enabled)) { $nbElements = 0; // Enable caching of thirdrparty count Contacts $cachekey = 'count_elements_project_'.$project->id; @@ -134,6 +134,9 @@ function project_prepare_head(Project $project, $moreparam = '') if (!is_null($dataretrieved)) { $nbElements = $dataretrieved; } else { + if (!empty($conf->stock->enabled)) { + $nbElements += $project->getElementCount('stock', 'entrepot', 'fk_project'); + } if (!empty($conf->propal->enabled)) { $nbElements += $project->getElementCount('propal', 'propal'); } diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 4c36244a5bf..da5d9388bd8 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -513,8 +513,8 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f if (!$user->rights->salaries->delete) { $deleteok = 0; } - } elseif ($feature == 'salaries') { - if (!$user->rights->salaries->delete) { + } elseif ($feature == 'adherent') { + if (!$user->rights->adherent->supprimer) { $deleteok = 0; } } elseif (!empty($feature2)) { // This is for permissions on 2 levels diff --git a/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php b/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php index b1f48450d0d..f5862bfc5f2 100644 --- a/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/expensereport/doc/pdf_standard.modules.php @@ -175,10 +175,11 @@ class pdf_standard extends ModeleExpenseReport //$this->posxdate=88; //$this->posxtype=107; //$this->posxprojet=120; - $this->posxtva = 130; - $this->posxup = 145; - $this->posxqty = 168; - $this->postotalttc = 178; + $this->posxtva = 112; + $this->posxup = 127; + $this->posxqty = 150; + $this->postotalht = 160; + $this->postotalttc = 180; // if (empty($conf->projet->enabled)) { // $this->posxtva-=20; // $this->posxup-=20; @@ -642,11 +643,15 @@ class pdf_standard extends ModeleExpenseReport // Quantity $pdf->SetXY($this->posxqty, $curY); - $pdf->MultiCell($this->postotalttc - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R'); + $pdf->MultiCell($this->postotalht - $this->posxqty - 0.8, 4, $object->lines[$linenumber]->qty, 0, 'R'); + + // Total without taxes + $pdf->SetXY($this->postotalht, $curY); + $pdf->MultiCell($this->postotalttc - $this->postotalht - 0.8, 4, price($object->lines[$linenumber]->total_ht), 0, 'R'); // Total with all taxes $pdf->SetXY($this->postotalttc - 1, $curY); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R'); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 4, price($object->lines[$linenumber]->total_ttc), 0, 'R'); // Comments $pdf->SetXY($this->posxcomment, $curY); @@ -950,14 +955,14 @@ class pdf_standard extends ModeleExpenseReport // Accountancy piece if (empty($hidetop)) { $pdf->SetXY($this->posxpiece - 1, $tab_top + 1); - $pdf->MultiCell($this->posxcomment - $this->posxpiece - 1, 1, '', '', 'R'); + $pdf->MultiCell($this->posxcomment - $this->posxpiece - 0.8, 1, '', '', 'R'); } // Comments $pdf->line($this->posxcomment - 1, $tab_top, $this->posxcomment - 1, $tab_top + $tab_height); if (empty($hidetop)) { $pdf->SetXY($this->posxcomment - 1, $tab_top + 1); - $pdf->MultiCell($this->posxdate - $this->posxcomment - 1, 1, $outputlangs->transnoentities("Description"), '', 'L'); + $pdf->MultiCell($this->posxdate - $this->posxcomment - 0.8, 1, $outputlangs->transnoentities("Description"), '', 'L'); } // Date @@ -990,7 +995,7 @@ class pdf_standard extends ModeleExpenseReport if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) { $pdf->line($this->posxtva - 1, $tab_top, $this->posxtva - 1, $tab_top + $tab_height); if (empty($hidetop)) { - $pdf->SetXY($this->posxtva - 1, $tab_top + 1); + $pdf->SetXY($this->posxtva - 0.8, $tab_top + 1); $pdf->MultiCell($this->posxup - $this->posxtva - 1, 2, $outputlangs->transnoentities("VAT"), '', 'C'); } } @@ -998,22 +1003,29 @@ class pdf_standard extends ModeleExpenseReport // Unit price $pdf->line($this->posxup - 1, $tab_top, $this->posxup - 1, $tab_top + $tab_height); if (empty($hidetop)) { - $pdf->SetXY($this->posxup - 1, $tab_top + 1); - $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceU"), '', 'C'); + $pdf->SetXY($this->posxup - 0.8, $tab_top + 1); + $pdf->MultiCell($this->posxqty - $this->posxup - 1, 2, $outputlangs->transnoentities("PriceUTTC"), '', 'C'); } // Quantity $pdf->line($this->posxqty - 1, $tab_top, $this->posxqty - 1, $tab_top + $tab_height); if (empty($hidetop)) { - $pdf->SetXY($this->posxqty - 1, $tab_top + 1); - $pdf->MultiCell($this->postotalttc - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C'); + $pdf->SetXY($this->posxqty - 0.8, $tab_top + 1); + $pdf->MultiCell($this->postotalht - $this->posxqty - 1, 2, $outputlangs->transnoentities("Qty"), '', 'C'); + } + + // Total without taxes + $pdf->line($this->postotalht - 1, $tab_top, $this->postotalht - 1, $tab_top + $tab_height); + if (empty($hidetop)) { + $pdf->SetXY($this->postotalht - 0.8, $tab_top + 1); + $pdf->MultiCell($this->postotalttc - $this->postotalht + 1, 2, $outputlangs->transnoentities("TotalHT"), '', 'C'); } // Total with all taxes $pdf->line($this->postotalttc, $tab_top, $this->postotalttc, $tab_top + $tab_height); if (empty($hidetop)) { - $pdf->SetXY($this->postotalttc - 1, $tab_top + 1); - $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R'); + $pdf->SetXY($this->postotalttc - 0.8, $tab_top + 1); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalttc + 1, 2, $outputlangs->transnoentities("TotalTTC"), '', 'R'); } $pdf->SetTextColor(0, 0, 0); diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 84d0cfd452d..c36442915e6 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -2549,7 +2549,7 @@ if ($action == 'create') { // Presend form $modelmail = 'shipping_send'; $defaulttopic = 'SendShippingRef'; - $diroutput = $conf->expedition->dir_output.'/sending'; + $diroutput = $conf->expedition->dir_output; $trackid = 'shi'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 9941139ea19..7aa08d30c39 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -235,7 +235,7 @@ if (empty($reshook)) { $object->fk_user_author = $user->id; } - // Check that expense report is for a user inside the hierarchy or advanced permission for all is set + // Check that expense report is for a user inside the hierarchy, or that advanced permission for all is set if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->expensereport->creer) && empty($user->rights->expensereport->writeall_advance))) { $error++; @@ -1110,7 +1110,7 @@ if (empty($reshook)) { $action = ''; } - if ((int) $tmpvat < 0 || $tmpvat == '') { + if ((float) $tmpvat < 0 || $tmpvat === '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors'); $action = ''; @@ -1205,7 +1205,6 @@ if (empty($reshook)) { } } - $object->update_totaux_del($object_ligne->total_ht, $object_ligne->total_tva); header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOST('id', 'int')); exit; } else { @@ -1255,7 +1254,7 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors'); $action = ''; } - if ((int) $tmpvat < 0 || $tmpvat == '') { + if ((float) $tmpvat < 0 || $tmpvat == '') { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors'); $action = ''; @@ -1292,8 +1291,6 @@ if (empty($reshook)) { } } - $result = $object->recalculer($id); - //header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); //exit; } else { @@ -1453,8 +1450,6 @@ if ($action == 'create') { } elseif ($id > 0 || $ref) { $result = $object->fetch($id, $ref); - $res = $object->fetch_optionals(); - if ($result > 0) { if (!in_array($object->fk_user_author, $user->getAllChildIds(1))) { if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous) @@ -1852,12 +1847,22 @@ if ($action == 'create') { print ''; print ''; - print ''; + print ''; print ''; + // Amount Local Taxes + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1 + print ''; + print ''; + } + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2 IRPF + print ''; + print ''; + } + print ''; print ''; - print ''; + print ''; print ''; // List of payments already done @@ -2062,7 +2067,7 @@ if ($action == 'create') { // Comment print ''; // VAT rate - print ''; + print ''; // Unit price HT print ''; // VAT + $selectedvat = price2num($line->vatrate).($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''); print ''; // Unit price diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 66d5eb6d7c0..7610d7b53b1 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -80,8 +80,6 @@ class ExpenseReport extends CommonObject */ public $fk_statut; - public $vat_src_code; - public $fk_c_paiement; public $paid; @@ -124,6 +122,9 @@ class ExpenseReport extends CommonObject // Paiement public $user_paid_infos; + public $localtax1; // for backward compatibility (real field should be total_localtax1 defined into CommonObject) + public $localtax2; // for backward compatibility (real field should be total_localtax2 defined into CommonObject) + /** * Draft status @@ -213,6 +214,10 @@ class ExpenseReport extends CommonObject $this->total_ht = 0; $this->total_ttc = 0; $this->total_tva = 0; + $this->total_localtax1 = 0; + $this->total_localtax2 = 0; + $this->localtax1 = 0; // For backward compatibility + $this->localtax2 = 0; // For backward compatibility $this->modepaymentid = 0; // List of language codes for status @@ -314,12 +319,18 @@ class ExpenseReport extends CommonObject $newndfline->fk_project = $line->fk_project; $newndfline->vatrate = $line->vatrate; $newndfline->vat_src_code = $line->vat_src_code; + $newndfline->localtax1_tx = $line->localtax1_tx; + $newndfline->localtax2_tx = $line->localtax2_tx; + $newndfline->localtax1_type = $line->localtax1_type; + $newndfline->localtax2_type = $line->localtax2_type; $newndfline->comments = $line->comments; $newndfline->qty = $line->qty; $newndfline->value_unit = $line->value_unit; $newndfline->total_ht = $line->total_ht; $newndfline->total_ttc = $line->total_ttc; $newndfline->total_tva = $line->total_tva; + $newndfline->total_localtax1 = $line->total_localtax1; + $newndfline->total_localtax2 = $line->total_localtax2; $newndfline->date = $line->date; $newndfline->rule_warning_message = $line->rule_warning_message; $newndfline->fk_c_exp_tax_cat = $line->fk_c_exp_tax_cat; @@ -539,7 +550,8 @@ class ExpenseReport extends CommonObject $sql = "SELECT d.rowid, d.entity, d.ref, d.note_public, d.note_private,"; // DEFAULT $sql .= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS $sql .= " d.date_refuse, d.date_cancel,"; // ACTIONS - $sql .= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int) + $sql .= " d.total_ht, d.total_ttc, d.total_tva,"; + $sql .= " d.localtax1 as total_localtax1, d.localtax2 as total_localtax2,"; $sql .= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,"; // DATES (datetime) $sql .= " d.fk_user_creat, d.fk_user_author, d.fk_user_modif, d.fk_user_validator,"; $sql .= " d.fk_user_valid, d.fk_user_approve,"; @@ -565,6 +577,11 @@ class ExpenseReport extends CommonObject $this->total_ht = $obj->total_ht; $this->total_tva = $obj->total_tva; $this->total_ttc = $obj->total_ttc; + $this->localtax1 = $obj->total_localtax1; // For backward compatibility + $this->localtax2 = $obj->total_localtax2; // For backward compatibility + $this->total_localtax1 = $obj->total_localtax1; + $this->total_localtax2 = $obj->total_localtax2; + $this->note_public = $obj->note_public; $this->note_private = $obj->note_private; $this->detail_refuse = $obj->detail_refuse; @@ -962,54 +979,6 @@ class ExpenseReport extends CommonObject } } - /** - * recalculer - * TODO Replace this with call to update_price if not already done - * - * @param int $id Id of expense report - * @return int <0 if KO, >0 if OK - */ - public function recalculer($id) - { - $sql = 'SELECT tt.total_ht, tt.total_ttc, tt.total_tva'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as tt'; - $sql .= " WHERE tt.".$this->fk_element.' = '.((int) $id); - - $total_ht = 0; $total_tva = 0; $total_ttc = 0; - - $result = $this->db->query($sql); - if ($result) { - $num = $this->db->num_rows($result); - $i = 0; - while ($i < $num) { - $objp = $this->db->fetch_object($result); - $total_ht += $objp->total_ht; - $total_tva += $objp->total_tva; - $i++; - } - - $total_ttc = $total_ht + $total_tva; - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql .= " total_ht = ".((float) price2num($total_ht, 'MT')); - $sql .= " , total_ttc = ".((float) price2num($total_ttc, 'MT')); - $sql .= " , total_tva = ".((float) price2num($total_tva, 'MT')); - $sql .= " WHERE rowid = ".((int) $id); - $result = $this->db->query($sql); - if ($result) { - $this->db->free($result); - return 1; - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this)."::recalculer: Error ".$this->error, LOG_ERR); - return -3; - } - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this)."::recalculer: Error ".$this->error, LOG_ERR); - return -3; - } - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * fetch_lines @@ -1024,8 +993,12 @@ class ExpenseReport extends CommonObject $this->lines = array(); $sql = ' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date, de.rang,'; - $sql .= " de.".$this->fk_element.", de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project, de.tva_tx, de.fk_ecm_files,"; + $sql .= " de.".$this->fk_element.", de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project,"; + $sql .= ' de.tva_tx, de.vat_src_code,'; + $sql .= ' de.localtax1_tx, de.localtax2_tx, de.localtax1_type, de.localtax2_type,'; + $sql .= ' de.fk_ecm_files,'; $sql .= ' de.total_ht, de.total_tva, de.total_ttc,'; + $sql .= ' de.total_localtax1, de.total_localtax2,'; $sql .= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,'; $sql .= ' p.ref as ref_projet, p.title as title_projet'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de'; @@ -1065,11 +1038,20 @@ class ExpenseReport extends CommonObject $deplig->total_ht = $objp->total_ht; $deplig->total_tva = $objp->total_tva; $deplig->total_ttc = $objp->total_ttc; + $deplig->total_localtax1 = $objp->total_localtax1; + $deplig->total_localtax2 = $objp->total_totaltax2; $deplig->type_fees_code = empty($objp->code_type_fees) ? 'TF_OTHER' : $objp->code_type_fees; $deplig->type_fees_libelle = $objp->libelle_type_fees; - $deplig->tva_tx = $objp->tva_tx; + + $deplig->tva_tx = $objp->tva_tx; $deplig->vatrate = $objp->tva_tx; + $deplig->vat_src_code = $objp->vat_src_code; + $deplig->localtax1_tx = $objp->localtax1_tx; + $deplig->localtax2_tx = $objp->localtax2_tx; + $deplig->localtax1_type = $objp->localtax1_type; + $deplig->localtax2_type = $objp->localtax2_type; + $deplig->projet_ref = $objp->ref_projet; $deplig->projet_title = $objp->title_projet; @@ -1757,41 +1739,11 @@ class ExpenseReport extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Update total of an expense report when you delete a line. - * - * @param string $ligne_total_ht Amount without taxes - * @param string $ligne_total_tva Amount of all taxes - * @return void - */ - public function update_totaux_del($ligne_total_ht, $ligne_total_tva) - { - // phpcs:enable - $this->total_ht = $this->total_ht - $ligne_total_ht; - $this->total_tva = $this->total_tva - $ligne_total_tva; - $this->total_ttc = $this->total_ht + $this->total_tva; - - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - $sql .= " total_ht = ".$this->total_ht; - $sql .= " , total_ttc = ".$this->total_ttc; - $sql .= " , total_tva = ".$this->total_tva; - $sql .= " WHERE rowid = ".((int) $this->id); - - $result = $this->db->query($sql); - if ($result) { - return 1; - } else { - $this->error = $this->db->error(); - return -1; - } - } - - /** - * addline + * Add expense report line * * @param float $qty Qty - * @param double $up Value init + * @param double $up Unit price (price with tax) * @param int $fk_c_type_fees Type payment * @param string $vatrate Vat rate (Can be '10' or '10 (ABC)') * @param string $date Date @@ -1838,7 +1790,14 @@ class ExpenseReport extends CommonObject $this->line = new ExpenseReportLine($this->db); - $localtaxes_type = getLocalTaxesFromRate($vatrate, 0, $mysoc, $this->thirdparty); + // We don't know seller and buyer for expense reports + $seller = $mysoc; // We use same than current company (expense report are often done in same country) + $seller->tva_assuj = 1; // Most seller uses vat + $seller->localtax1_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + $seller->localtax2_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + $buyer = new Societe($this->db); + + $localtaxes_type = getLocalTaxesFromRate($vatrate, 0, $buyer, $seller); $vat_src_code = ''; $reg = array(); @@ -1848,16 +1807,22 @@ class ExpenseReport extends CommonObject } $vatrate = preg_replace('/\*/', '', $vatrate); - $seller = ''; // seller is unknown - - $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + $tmp = calcul_price_total($qty, $up, 0, $vatrate, -1, -1, 0, 'TTC', 0, $type, $seller, $localtaxes_type); $this->line->value_unit = $up; + $this->line->vat_src_code = $vat_src_code; $this->line->vatrate = price2num($vatrate); + $this->line->localtax1_tx = $localtaxes_type[1]; + $this->line->localtax2_tx = $localtaxes_type[3]; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->total_ttc = $tmp[2]; $this->line->total_ht = $tmp[0]; $this->line->total_tva = $tmp[1]; + $this->line->total_localtax1 = $tmp[9]; + $this->line->total_localtax2 = $tmp[10]; $this->line->fk_expensereport = $this->id; $this->line->qty = $qty; @@ -1899,13 +1864,13 @@ class ExpenseReport extends CommonObject /** * Check constraint of rules and update price if needed * - * @param int $type type of line - * @param string $seller seller, but actually he is unknown - * @return true or false + * @param int $type Type of line + * @param string $seller Seller, but actually he is unknown + * @return true or false */ public function checkRules($type = 0, $seller = '') { - global $user, $conf, $db, $langs; + global $user, $conf, $db, $langs, $mysoc; $langs->load('trips'); @@ -1913,6 +1878,15 @@ class ExpenseReport extends CommonObject return true; // if don't use rules } + // We don't know seller and buyer for expense reports + if (!is_object($seller)) { + $seller = $mysoc; // We use same than current company (expense report are often done in same country) + $seller->tva_assuj = 1; // Most seller uses vat + $seller->localtax1_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + $seller->localtax2_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + } + //$buyer = new Societe($this->db); + $rulestocheck = ExpenseReportRule::getAllRule($this->line->fk_c_type_fees, $this->line->date, $this->fk_user_author); $violation = 0; @@ -1960,6 +1934,8 @@ class ExpenseReport extends CommonObject $this->line->total_ttc = $tmp[2]; $this->line->total_ht = $tmp[0]; $this->line->total_tva = $tmp[1]; + $this->line->total_localtax1 = $tmp[9]; + $this->line->total_localtax2 = $tmp[10]; return false; } else { @@ -1970,11 +1946,13 @@ class ExpenseReport extends CommonObject /** * Method to apply the offset if needed * - * @return boolean true=applied, false=not applied + * @param int $type Type of line + * @param string $seller Seller, but actually he is unknown + * @return boolean True=applied, False=not applied */ - public function applyOffset() + public function applyOffset($type = 0, $seller = '') { - global $conf; + global $conf, $mysoc; if (empty($conf->global->MAIN_USE_EXPENSE_IK)) { return false; @@ -1987,6 +1965,15 @@ class ExpenseReport extends CommonObject return false; } + // We don't know seller and buyer for expense reports + if (!is_object($seller)) { + $seller = $mysoc; // We use same than current company (expense report are often done in same country) + $seller->tva_assuj = 1; // Most seller uses vat + $seller->localtax1_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + $seller->localtax2_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + } + //$buyer = new Societe($this->db); + $range = ExpenseReportIk::getRangeByUser($userauthor, $this->line->fk_c_exp_tax_cat); if (empty($range)) { @@ -2010,6 +1997,8 @@ class ExpenseReport extends CommonObject $this->line->total_ttc = $tmp[2]; $this->line->total_ht = $tmp[0]; $this->line->total_tva = $tmp[1]; + $this->line->total_localtax1 = $tmp[9]; + $this->line->total_localtax2 = $tmp[10]; return true; } @@ -2033,7 +2022,7 @@ class ExpenseReport extends CommonObject $sql .= ' AND d.rowid <> '.((int) $this->line->id); } - dol_syslog(get_class($this)."::offsetAlreadyGiven sql=".$sql); + dol_syslog(get_class($this)."::offsetAlreadyGiven"); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -2056,7 +2045,7 @@ class ExpenseReport extends CommonObject * @param double $vatrate Vat rate. Can be '8.5' or '8.5* (8.5NPROM...)' * @param string $comments Description * @param float $qty Qty - * @param double $value_unit Value init + * @param double $value_unit Unit price (with taxes) * @param int $date Date * @param int $expensereport_id Expense report id * @param int $fk_c_exp_tax_cat Id of category of car @@ -2073,7 +2062,10 @@ class ExpenseReport extends CommonObject $type = 0; // TODO What if type is service ? // We don't know seller and buyer for expense reports - $seller = $mysoc; + $seller = $mysoc; // We use same than current company (expense report are often done in same country) + $seller->tva_assuj = 1; // Most seller uses vat + $seller->localtax1_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company + $seller->localtax2_assuj = $mysoc->localtax1_assuj; // We don't know, we reuse the state of company $buyer = new Societe($this->db); $localtaxes_type = getLocalTaxesFromRate($vatrate, 0, $buyer, $seller); @@ -2087,8 +2079,8 @@ class ExpenseReport extends CommonObject } $vatrate = preg_replace('/\*/', '', $vatrate); - $tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); - + $tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, -1, -1, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + //var_dump($vatrate);var_dump($localtaxes_type);var_dump($tmp);exit; // calcul total of line //$total_ttc = price2num($qty*$value_unit, 'MT'); @@ -2109,14 +2101,17 @@ class ExpenseReport extends CommonObject $this->line->vat_src_code = $vat_src_code; $this->line->vatrate = price2num($vatrate); - $this->line->total_ttc = $tmp[2]; - $this->line->total_ht = $tmp[0]; - $this->line->total_tva = $tmp[1]; $this->line->localtax1_tx = $localtaxes_type[1]; $this->line->localtax2_tx = $localtaxes_type[3]; $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->total_ttc = $tmp[2]; + $this->line->total_ht = $tmp[0]; + $this->line->total_tva = $tmp[1]; + $this->line->total_localtax1 = $tmp[9]; + $this->line->total_localtax2 = $tmp[10]; + $this->line->fk_ecm_files = $fk_ecm_files; $this->line->id = ((int) $rowid); @@ -2184,6 +2179,8 @@ class ExpenseReport extends CommonObject return -1; } + $this->update_price(); + $this->db->commit(); return 1; @@ -2593,9 +2590,17 @@ class ExpenseReportLine public $projet_title; public $vatrate; + public $vat_src_code; + public $localtax1_tx; + public $localtax2_tx; + public $localtax1_type; + public $localtax2_type; + public $total_ht; public $total_tva; public $total_ttc; + public $total_localtax1; + public $total_localtax2; /** * @var int ID into llx_ecm_files table to link line to attached file @@ -2623,6 +2628,7 @@ class ExpenseReportLine { $sql = 'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_c_exp_tax_cat, fde.fk_projet as fk_project, fde.date,'; $sql .= ' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc, fde.fk_ecm_files,'; + $sql .= ' fde.localtax1_tx, fde.localtax2_tx, fde.localtax1_type, fde.localtax2_type, fde.total_localtax1, fde.total_localtax2,'; $sql .= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; $sql .= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; $sql .= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; @@ -2652,11 +2658,20 @@ class ExpenseReportLine $this->type_fees_libelle = $objp->type_fees_libelle; $this->projet_ref = $objp->projet_ref; $this->projet_title = $objp->projet_title; + $this->vatrate = $objp->vatrate; $this->vat_src_code = $objp->vat_src_code; + $this->localtax1_tx = $objp->localtax1_tx; + $this->localtax2_tx = $objp->localtax2_tx; + $this->localtax1_type = $objp->localtax1_type; + $this->localtax2_type = $objp->localtax2_type; + $this->total_ht = $objp->total_ht; $this->total_tva = $objp->total_tva; $this->total_ttc = $objp->total_ttc; + $this->total_localtax1 = $objp->total_localtax1; + $this->total_localtax2 = $objp->total_localtax2; + $this->fk_ecm_files = $objp->fk_ecm_files; $this->db->free($result); @@ -2695,18 +2710,29 @@ class ExpenseReportLine $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'expensereport_det'; $sql .= ' (fk_expensereport, fk_c_type_fees, fk_projet,'; - $sql .= ' tva_tx, vat_src_code, comments, qty, value_unit, total_ht, total_tva, total_ttc, date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)'; + $sql .= ' tva_tx, vat_src_code,'; + $sql .= ' localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; + $sql .= ' comments, qty, value_unit,'; + $sql .= ' total_ht, total_tva, total_ttc,'; + $sql .= ' total_localtax1, total_localtax2,'; + $sql .= ' date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)'; $sql .= " VALUES (".$this->db->escape($this->fk_expensereport).","; $sql .= " ".((int) $this->fk_c_type_fees).","; $sql .= " ".((int) (!empty($this->fk_project) && $this->fk_project > 0) ? $this->fk_project : ((!empty($this->fk_projet) && $this->fk_projet > 0) ? $this->fk_projet : 'null')).","; $sql .= " ".((float) $this->vatrate).","; $sql .= " '".$this->db->escape(empty($this->vat_src_code) ? '' : $this->vat_src_code)."',"; + $sql .= " ".((float) price2num($this->localtax1_tx)).","; + $sql .= " ".((float) price2num($this->localtax2_tx)).","; + $sql .= " '".$this->db->escape($this->localtax1_type)."',"; + $sql .= " '".$this->db->escape($this->localtax2_type)."',"; $sql .= " '".$this->db->escape($this->comments)."',"; $sql .= " ".((float) $this->qty).","; $sql .= " ".((float) $this->value_unit).","; $sql .= " ".((float) price2num($this->total_ht)).","; $sql .= " ".((float) price2num($this->total_tva)).","; $sql .= " ".((float) price2num($this->total_ttc)).","; + $sql .= " ".((float) price2num($this->total_localtax1)).","; + $sql .= " ".((float) price2num($this->total_localtax2)).","; $sql .= " '".$this->db->idate($this->date)."',"; $sql .= " ".(empty($this->rule_warning_message) ? 'null' : "'".$this->db->escape($this->rule_warning_message)."'").","; $sql .= " ".((int) $this->fk_c_exp_tax_cat).","; @@ -2814,11 +2840,17 @@ class ExpenseReportLine $sql .= ", value_unit = ".((float) $this->value_unit); $sql .= ", qty=".((float) $this->qty); $sql .= ", date='".$this->db->idate($this->date)."'"; - $sql .= ", total_ht=".((float) price2num($this->total_ht, 'MT')).""; - $sql .= ", total_tva=".((float) price2num($this->total_tva, 'MT')).""; - $sql .= ", total_ttc=".((float) price2num($this->total_ttc, 'MT')).""; + $sql .= ", total_ht=".((float) price2num($this->total_ht, 'MT')); + $sql .= ", total_tva=".((float) price2num($this->total_tva, 'MT')); + $sql .= ", total_ttc=".((float) price2num($this->total_ttc, 'MT')); + $sql .= ", total_localtax1=".((float) price2num($this->total_localtax1, 'MT')); + $sql .= ", total_localtax2=".((float) price2num($this->total_localtax2, 'MT')); $sql .= ", tva_tx=".((float) $this->vatrate); $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'"; + $sql .= ", localtax1_tx=".((float) $this->localtax1_tx); + $sql .= ", localtax2_tx=".((float) $this->localtax2_tx); + $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'"; + $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'"; $sql .= ", rule_warning_message='".$this->db->escape($this->rule_warning_message)."'"; $sql .= ", fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat); $sql .= ", fk_ecm_files=".($this->fk_ecm_files > 0 ? ((int) $this->fk_ecm_files) : 'null'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 9b1da2aa530..762436a3a0e 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -695,6 +695,7 @@ if (empty($reshook)) { if ($socid > 0) { $object->socid = GETPOST('socid', 'int'); } + $selectedLines = GETPOST('toselect', 'array'); $db->begin(); @@ -1131,6 +1132,10 @@ if (empty($reshook)) { $num = count($lines); for ($i = 0; $i < $num; $i++) { // TODO handle subprice < 0 + if (!in_array($lines[$i]->id, $selectedLines)) { + continue; // Skip unselected lines + } + $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0); @@ -2363,9 +2368,6 @@ if ($action == 'create') { print $form->buttonsSaveCancel("CreateDraft"); - print "\n"; - - // Show origin lines if (is_object($objectsrc)) { print '
'; @@ -2379,6 +2381,8 @@ if ($action == 'create') { print '
'.$langs->trans("Filter").'
'.$langs->trans("ThirdParty").''; -if ($mode == 'customer') { - $filter = 's.client in (1,2,3)'; -} -if ($mode == 'supplier') { - $filter = 's.fournisseur = 1'; -} print img_picto('', 'company', 'class="pictofixedwidth"'); -print $form->selectarray('socid', $companies, $socid, 1, 0, 0, '', 0, 0, 0, '', 'widthcentpercentminusx maxwidth300', 1); +print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, 'widthcentpercentminusx maxwidth300'); print '
'.$langs->trans("AmountVAT").''.price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency).''.price($object->total_tva, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).''.price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency).'
'.dol_nl2br($line->comments).''.vatrate($line->vatrate, true).''.vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true).''; if (!empty($line->value_unit_ht)) { @@ -2269,8 +2274,9 @@ if ($action == 'create') { print ''; - print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $line->vatrate), $mysoc, '', 0, 0, '', false, 1); + print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $selectedvat), $mysoc, '', 0, 0, '', false, 1); print '
'; } + + print "\n"; } else { if ($id > 0 || !empty($ref)) { // diff --git a/htdocs/install/mysql/tables/llx_eventorganization_conferenceorboothattendee.sql b/htdocs/install/mysql/tables/llx_eventorganization_conferenceorboothattendee.sql index 6d01cf4bba1..b505f8f6a31 100644 --- a/htdocs/install/mysql/tables/llx_eventorganization_conferenceorboothattendee.sql +++ b/htdocs/install/mysql/tables/llx_eventorganization_conferenceorboothattendee.sql @@ -21,6 +21,7 @@ CREATE TABLE llx_eventorganization_conferenceorboothattendee( fk_soc integer, fk_actioncomm integer, fk_project integer NOT NULL, + fk_invoice integer NULL, email varchar(100), date_subscription datetime, amount double DEFAULT NULL, diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index f2cb92efc7f..27d34e2aa51 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -144,11 +144,6 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port); - // Create the global $hookmanager object - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager = new HookManager($db); - $hookmanager->initHooks(array('upgrade')); - if (!$db->connected) { print ''.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).''.$langs->trans('Error').''; dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR); @@ -182,6 +177,11 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; } + // Create the global $hookmanager object + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($db); + $hookmanager->initHooks(array('upgrade')); + /*************************************************************************************** * diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index a73f06e1201..53355dd15ce 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -898,6 +898,11 @@ Permission1002=Create/modify warehouses Permission1003=Delete warehouses Permission1004=Read stock movements Permission1005=Create/modify stock movements +Permission1011=View inventories +Permission1012=Create new inventory +Permission1014=Validate inventory +Permission1015=Allow to change PMP value for a product +Permission1016=Delete inventory Permission1101=Read delivery receipts Permission1102=Create/modify delivery receipts Permission1104=Validate delivery receipts diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b799113af29..b624c0f231e 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1016,7 +1016,6 @@ class Product extends CommonObject $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export); - $this->db->begin(); $result = 0; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 67912d4acab..72af7b6e886 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004-2021 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2012 Juanjo Menent @@ -54,7 +54,9 @@ $cancel = GETPOST('cancel', 'alpha'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'pricesuppliercard'; $socid = GETPOST('socid', 'int'); -$cost_price = GETPOST('cost_price', 'alpha'); +$cost_price = price2num(GETPOST('cost_price', 'alpha'), '', 2); +$pmp = price2num(GETPOST('pmp', 'alpha'), '', 2); + $backtopage = GETPOST('backtopage', 'alpha'); $error = 0; @@ -147,13 +149,29 @@ if (empty($reshook)) { } } } + if ($action == 'setpmp') { + if ($id) { + $result = $object->fetch($id); + $object->pmp = price2num($pmp); + $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".((float) $object->pmp)." WHERE rowid = ".((int) $id); + $resql = $db->query($sql); + //$result = $object->update($object->id, $user); + if ($resql) { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); + $action = ''; + } else { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } if ($action == 'confirm_remove_pf') { if ($rowid) { // id of product supplier price to remove $action = ''; $result = $object->remove_product_fournisseur_price($rowid); if ($result > 0) { - $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = $rowid"); + $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".((int) $rowid)); setEventMessages($langs->trans("PriceRemoved"), null, 'mesgs'); } else { $error++; @@ -425,11 +443,25 @@ if ($id > 0 || $ref) { print ''; // PMP - print ''.$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).''; + $usercaneditpmp = 0; + if (!empty($conf->global->PRODUCT_CAN_EDIT_WAP)) { + $usercaneditpmp = $usercancreate; + } + print ''; + $textdesc = $langs->trans("AverageUnitPricePMPDesc"); + $text = $form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $textdesc, 1, 'help', ''); + print $form->editfieldkey($text, 'pmp', $object->pmp, $object, $usercaneditpmp, 'amount:6'); + print ''; + print $form->editfieldval($text, 'pmp', ($object->pmp > 0 ? $object->pmp : ''), $object, $usercaneditpmp, 'amount:6'); + if ($object->pmp > 0) { + print ' '.$langs->trans("HT"); + } + /* + .$form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")).''; print ''; if ($object->pmp > 0) { print price($object->pmp).' '.$langs->trans("HT"); - } + }*/ print ''; print ''; diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 7fcfe3bc92b..9e14a53e7ea 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -36,6 +36,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +if (!empty($conf->stock->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; +} if (!empty($conf->propal->enabled)) { require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; } diff --git a/htdocs/public/eventorganization/attendee_register.php b/htdocs/public/eventorganization/attendee_register.php index db3acde4628..a454f214316 100644 --- a/htdocs/public/eventorganization/attendee_register.php +++ b/htdocs/public/eventorganization/attendee_register.php @@ -330,63 +330,63 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email); } } - if ($resultfetchthirdparty <= 0 && !empty($emailcompany)) { - // Try to find thirdparty from the email only - $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $emailcompany); - if ($resultfetchthirdparty > 0) { - // We found a unique result with that email only, so we set the fk_soc of attendee - $confattendee->fk_soc = $thirdparty->id; - $confattendee->update($user); - } elseif ($resultfetchthirdparty == -2) { - $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email); - } + } + if ($resultfetchthirdparty <= 0 && !empty($emailcompany)) { + // Try to find thirdparty from the email only + $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $emailcompany); + if ($resultfetchthirdparty > 0) { + // We found a unique result with that email only, so we set the fk_soc of attendee + $confattendee->fk_soc = $thirdparty->id; + $confattendee->update($user); + } elseif ($resultfetchthirdparty == -2) { + $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email); } - if ($resultfetchthirdparty <= 0 && !empty($email) && $email != $emailcompany) { - // Try to find thirdparty from the email only - $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); - if ($resultfetchthirdparty > 0) { - // We found a unique result with that email only, so we set the fk_soc of attendee - $confattendee->fk_soc = $thirdparty->id; - $confattendee->update($user); - } elseif ($resultfetchthirdparty == -2) { - $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email); - } + } + if ($resultfetchthirdparty <= 0 && !empty($email) && $email != $emailcompany) { + // Try to find thirdparty from the email only + $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); + if ($resultfetchthirdparty > 0) { + // We found a unique result with that email only, so we set the fk_soc of attendee + $confattendee->fk_soc = $thirdparty->id; + $confattendee->update($user); + } elseif ($resultfetchthirdparty == -2) { + $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email); } - if ($resultfetchthirdparty <= 0 && !empty($genericcompanyname)) { - // Try to find thirdparty from the generic mail only - $resultfetchthirdparty = $thirdparty->fetch('', $genericcompanyname, '', '', '', '', '', '', '', '', ''); - if ($resultfetchthirdparty > 0) { - // We found a unique result with that name + email, so we set the fk_soc of attendee - $confattendee->fk_soc = $thirdparty->id; - $confattendee->update($user); - } elseif ($resultfetchthirdparty == -2) { - $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email); - } + } + if ($resultfetchthirdparty <= 0 && !empty($genericcompanyname)) { + // Try to find thirdparty from the generic mail only + $resultfetchthirdparty = $thirdparty->fetch('', $genericcompanyname, '', '', '', '', '', '', '', '', ''); + if ($resultfetchthirdparty > 0) { + // We found a unique result with that name + email, so we set the fk_soc of attendee + $confattendee->fk_soc = $thirdparty->id; + $confattendee->update($user); + } elseif ($resultfetchthirdparty == -2) { + $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email); } + } - // TODO Add more tests on a VAT number, profid or a name ? + // TODO Add more tests on a VAT number, profid or a name ? - if ($resultfetchthirdparty <= 0 && !empty($email)) { - // Try to find the thirdparty from the contact - $resultfetchcontact = $contact->fetch('', null, '', $email); - if ($resultfetchcontact > 0 && $contact->fk_soc > 0) { - $thirdparty->fetch($contact->fk_soc); - $confattendee->fk_soc = $thirdparty->id; - $confattendee->update($user); - $resultfetchthirdparty = 1; - } + if ($resultfetchthirdparty <= 0 && !empty($email)) { + // Try to find the thirdparty from the contact + $resultfetchcontact = $contact->fetch('', null, '', $email); + if ($resultfetchcontact > 0 && $contact->fk_soc > 0) { + $thirdparty->fetch($contact->fk_soc); + $confattendee->fk_soc = $thirdparty->id; + $confattendee->update($user); + $resultfetchthirdparty = 1; } + } - if ($resultfetchthirdparty <= 0 && !empty($societe)) { - // Try to find thirdparty from the company name only - $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', ''); - if ($resultfetchthirdparty > 0) { - // We found a unique result with that name only, so we set the fk_soc of attendee - $confattendee->fk_soc = $thirdparty->id; - $confattendee->update($user); - } elseif ($resultfetchthirdparty == -2) { - $thirdparty->error = "ErrorSeveralCompaniesWithNameContactUs"; - } + if ($resultfetchthirdparty <= 0 && !empty($societe)) { + // Try to find thirdparty from the company name only + $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', ''); + if ($resultfetchthirdparty > 0) { + // We found a unique result with that name only, so we set the fk_soc of attendee + $confattendee->fk_soc = $thirdparty->id; + $confattendee->update($user); + } elseif ($resultfetchthirdparty == -2) { + $thirdparty->error = "ErrorSeveralCompaniesWithNameContactUs"; } } } @@ -450,6 +450,7 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen } if (!$error) { + // If the registration needs a payment if (!empty(floatval($project->price_registration))) { $outputlangs = $langs; @@ -515,11 +516,14 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen $date_start = $project->date_start; $date_end = $project->date_end; - $result = $facture->addline($labelforproduct, floatval($project->price_registration), 1, $vattouse, 0, 0, $productforinvoicerow->id, 0, $date_start, $date_end, 0, 0, '', 'HT', 0, 1); - if ($result <= 0) { - $confattendee->error = $facture->error; - $confattendee->errors = $facture->errors; - $error++; + // If there is no lines yet, we add one + if (empty($facture->lines)) { + $result = $facture->addline($labelforproduct, floatval($project->price_registration), 1, $vattouse, 0, 0, $productforinvoicerow->id, 0, $date_start, $date_end, 0, 0, '', 'HT', 0, 1); + if ($result <= 0) { + $confattendee->error = $facture->error; + $confattendee->errors = $facture->errors; + $error++; + } } } diff --git a/htdocs/user/list.php b/htdocs/user/list.php index 89f9191751b..e302a0fac85 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -371,7 +371,7 @@ if ($search_supervisor > 0) { if ($search_thirdparty != '') { $sql .= natural_search(array('s.nom'), $search_thirdparty); } -if ($search_warehouse != '') { +if ($search_warehouse > 0) { $sql .= natural_search(array('u.fk_warehouse'), $search_warehouse); } if ($search_login != '') {