From b2eca0a3148b5ada5418afbea03abbdaa017a5da Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Tue, 19 Jan 2021 12:02:05 +0100 Subject: [PATCH] FIX : VAT declaration list + migration script --- htdocs/compta/tva/list.php | 102 +++++++----------- .../install/mysql/migration/13.0.0-14.0.0.sql | 33 ++++++ 2 files changed, 74 insertions(+), 61 deletions(-) diff --git a/htdocs/compta/tva/list.php b/htdocs/compta/tva/list.php index a142518279f..13cb2ad7386 100644 --- a/htdocs/compta/tva/list.php +++ b/htdocs/compta/tva/list.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2011-2019 Alexandre Spangaro * Copyright (C) 2020 Tobias Sekan + * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,6 +58,7 @@ $search_type = GETPOST('search_type', 'int'); $search_cheque = GETPOST('search_cheque', 'alpha'); $search_account = GETPOST('search_account', 'int'); $search_amount = GETPOST('search_amount', 'alpha'); +$search_status = GETPOST('search_status', 'int'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'alpha'); @@ -75,12 +77,9 @@ $arrayfields = array( 't.rowid' =>array('checked'=>1, 'position'=>10, 'label'=>"Ref",), 't.label' =>array('checked'=>1, 'position'=>20, 'label'=>"Label"), 't.datev' =>array('checked'=>1, 'position'=>30, 'label'=>"PeriodEndDate"), - 't.datep' =>array('checked'=>1, 'position'=>40, 'label'=>"DatePayment"), 't.fk_typepayment' =>array('checked'=>1, 'position'=>50, 'label'=>"Type"), - 't.num_payment' =>array('checked'=>1, 'position'=>60, 'label'=>"Numero", 'tooltip'=>"ChequeOrTransferNumber"), - 'transaction' =>array('checked'=>1, 'position'=>70, 'label'=>"BankTransactionLine", 'enabled'=>(!empty($conf->banque->enabled))), - 'ba.label' =>array('checked'=>1, 'position'=>80, 'label'=>"Account", 'enable'=>(!empty($conf->banque->enabled))), - 't.amount' =>array('checked'=>1, 'position'=>90, 'label'=>"PayedByThisPayment"), + 't.amount' =>array('checked'=>1, 'position'=>90, 'label'=>"Amount"), + 't.status' =>array('checked'=>1, 'position'=>90, 'label'=>"Status"), ); $arrayfields = dol_sort_array($arrayfields, 'position'); @@ -113,6 +112,7 @@ if (empty($reshook)) { $search_cheque = ''; $search_account = ''; $search_amount = ''; + $search_status = ''; } } @@ -128,15 +128,13 @@ $bankstatic = new Account($db); $accountingjournal = new AccountingJournal($db); $bankline = new AccountLine($db); -llxHeader('', $langs->trans("VATPayments")); +llxHeader('', $langs->trans("VATDeclarations")); -$sql = 'SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.fk_typepayment as type, t.num_payment, t.fk_bank'; -$sql .= ', ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel'; -$sql .= ', pst.code as payment_code'; +$sql = 'SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepayment as type, t.num_payment, pst.code as payment_code,'; +$sql .= ' SUM(ptva.amount) as alreadypayed'; $sql .= ' FROM '.MAIN_DB_PREFIX.'tva as t'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pst ON t.fk_typepayment = pst.id'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementtva as ptva ON ptva.fk_tva = t.rowid"; $sql .= ' WHERE t.entity IN ('.getEntity($object->element).')'; if (!empty($search_ref)) $sql .= natural_search('t.rowid', $search_ref); @@ -146,10 +144,11 @@ if (!empty($search_dateend_end)) $sql .= ' AND t.datev <= "'.$db->idate($sea if (!empty($search_datepayment_start)) $sql .= ' AND t.datep >= "'.$db->idate($search_datepayment_start).'"'; if (!empty($search_datepayment_end)) $sql .= ' AND t.datep <= "'.$db->idate($search_datepayment_end).'"'; if (!empty($search_type) && $search_type > 0) $sql .= ' AND t.fk_typepayment='.$search_type; -if (!empty($search_cheque)) $sql .= natural_search('t.num_payment', $search_cheque); if (!empty($search_account) && $search_account > 0) $sql .= ' AND b.fk_account='.$search_account; if (!empty($search_amount)) $sql .= natural_search('t.amount', price2num(trim($search_amount)), 1); +if ($search_status != '' && $search_status >= 0) $sql .= " AND t.paye = ".$db->escape($search_status); +$sql .= " GROUP BY t.rowid, t.amount, t.datev, t.label, t.paye"; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; @@ -200,6 +199,7 @@ if (!empty($search_type) && $search_type > 0) $param .= '&search_type='.$search if (!empty($search_cheque)) $param .= '&search_cheque="'.$search_cheque.'"'; if (!empty($search_account) && $search_account > 0) $param .= '&search_account='.$search_account; if (!empty($search_amount)) $param .= '&search_amount="'.$search_amount.'"'; +if ($search_status != '' && $search_status != '-1') $param .= '&search_status='.urlencode($search_status); print '
'; if ($optioncss != '') print ''; @@ -213,7 +213,7 @@ print ''; $url = DOL_URL_ROOT.'/compta/tva/card.php?action=create'; if (!empty($socid)) $url .= '&socid='.$socid; $newcardbutton = dolGetButtonTitle($langs->trans('NewVATPayment', ($ltt + 1)), '', 'fa fa-plus-circle', $url, '', $user->rights->tax->charges->creer); -print_barre_liste($langs->trans("VATPayments"), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); +print_barre_liste($langs->trans("VATDeclarations"), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); $varpage = empty($contextpage) ? $_SERVER['PHP_SELF'] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields @@ -257,7 +257,7 @@ if (!empty($arrayfields['t.datev']['checked'])) { } // Filter: Date payment -if (!empty($arrayfields['t.datep']['checked'])) { +/*if (!empty($arrayfields['t.datep']['checked'])) { print ''; print '
'; print $form->selectDate($search_datepayment_start ? $search_datepayment_start : -1, 'search_datepayment_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); @@ -266,7 +266,7 @@ if (!empty($arrayfields['t.datep']['checked'])) { print $form->selectDate($search_datepayment_end ? $search_datepayment_end : -1, 'search_datepayment_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); print '
'; print ''; -} +}*/ // Filter: Type if (!empty($arrayfields['t.fk_typepayment']['checked'])) { @@ -275,26 +275,6 @@ if (!empty($arrayfields['t.fk_typepayment']['checked'])) { print ''; } -// Filter: Cheque number -if (!empty($arrayfields['t.num_payment']['checked'])) { - print ''; - print ''; - print ''; -} - -// Filter: Bank transaction number (placeholder) -if (!empty($arrayfields['transaction']['checked'])) { - print ''; - print ''; -} - -// Filter: Bank account -if (!empty($arrayfields['ba.label']['checked'])) { - print ''; - $form->select_comptes($search_account, 'search_account', 0, '', 1); - print ''; -} - // Filter: Amount if (!empty($arrayfields['t.amount']['checked'])) { print ''; @@ -302,6 +282,14 @@ if (!empty($arrayfields['t.amount']['checked'])) { print ''; } +// Status +if (!empty($arrayfields['t.status']['checked'])) { + print ''; + $liststatus = array('0' => $langs->trans("Unpaid"), '1' => $langs->trans("Paid")); + print $form->selectarray('search_status', $liststatus, $search_status, 1); + print ''; +} + // Fields from hook $parameters = array('arrayfields'=>$arrayfields); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook @@ -319,12 +307,9 @@ if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) print_liste_field_titr if (!empty($arrayfields['t.rowid']['checked'])) print_liste_field_titre($arrayfields['t.rowid']['label'], $_SERVER['PHP_SELF'], 't.rowid', '', $param, '', $sortfield, $sortorder); if (!empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER['PHP_SELF'], 't.label', '', $param, 'align="left"', $sortfield, $sortorder); if (!empty($arrayfields['t.datev']['checked'])) print_liste_field_titre($arrayfields['t.datev']['label'], $_SERVER['PHP_SELF'], 't.datev', '', $param, 'align="center"', $sortfield, $sortorder); -if (!empty($arrayfields['t.datep']['checked'])) print_liste_field_titre($arrayfields['t.datep']['label'], $_SERVER['PHP_SELF'], 't.datep', '', $param, 'align="center"', $sortfield, $sortorder); if (!empty($arrayfields['t.fk_typepayment']['checked'])) print_liste_field_titre($arrayfields['t.fk_typepayment']['label'], $_SERVER['PHP_SELF'], 't.fk_typepayment', '', $param, '', $sortfield, $sortorder, 'left '); -if (!empty($arrayfields['t.num_payment']['checked'])) print_liste_field_titre($arrayfields['t.num_payment']['label'], $_SERVER['PHP_SELF'], 't.num_payment', '', $param, '', $sortfield, $sortorder, '', $arrayfields['t.num_payment']['tooltip']); -if (!empty($arrayfields['transaction']['checked'])) print_liste_field_titre($arrayfields['transaction']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder); -if (!empty($arrayfields['ba.label']['checked'])) print_liste_field_titre($arrayfields['ba.label']['label'], $_SERVER['PHP_SELF'], 'ba.label', '', $param, '', $sortfield, $sortorder, 'left '); if (!empty($arrayfields['t.amount']['checked'])) print_liste_field_titre($arrayfields['t.amount']['label'], $_SERVER['PHP_SELF'], 't.amount', '', $param, '', $sortfield, $sortorder, 'right '); +if (!empty($arrayfields['t.status']['checked'])) print_liste_field_titre($arrayfields['t.status']['label'], $_SERVER["PHP_SELF"], "t.paye", "", $param, 'class="right"', $sortfield, $sortorder); // Hook fields $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); @@ -369,10 +354,10 @@ while ($i < min($num, $limit)) { } // Date payment - if (!empty($arrayfields['t.datep']['checked'])) { + /*if (!empty($arrayfields['t.datep']['checked'])) { print ''.dol_print_date($db->jdate($obj->datep), 'day').''; if (!$i) $totalarray['nbfield']++; - } + }*/ // Type if (!empty($arrayfields['t.fk_typepayment']['checked'])) @@ -381,21 +366,8 @@ while ($i < min($num, $limit)) { if (!$i) $totalarray['nbfield']++; } - // Cheque number - if (!empty($arrayfields['t.num_payment']['checked'])) { - print ''.$obj->num_payment.''; - if (!$i) $totalarray['nbfield']++; - } - - // Bank transaction - if (!empty($arrayfields['transaction']['checked'])) { - $bankline->fetch($obj->fk_bank); - print ''.$bankline->getNomUrl(1, 0).''; - if (!$i) $totalarray['nbfield']++; - } - // Account - if (!empty($arrayfields['ba.label']['checked'])) { + /*if (!empty($arrayfields['ba.label']['checked'])) { print ''; if ($obj->fk_bank > 0) { $bankstatic->id = $obj->bid; @@ -411,14 +383,22 @@ while ($i < min($num, $limit)) { } print ''; if (!$i) $totalarray['nbfield']++; - } + }*/ // Amount - $total = $total + $obj->amount; - print ''.price($obj->amount).''; - if (!$i) $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'amount'; - $totalarray['val']['amount'] += $objp->amount; + if (!empty($arrayfields['t.amount']['checked'])) { + $total = $total + $obj->amount; + print '' . price($obj->amount) . ''; + if (!$i) $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'amount'; + $totalarray['val']['amount'] += $obj->amount; + } + + if (!empty($arrayfields['t.status']['checked'])) { + print '' . $tva_static->LibStatut($obj->paye, 5, $obj->alreadypayed) . ''; + if (!$i) $totalarray['nbfield']++; + if(!empty($arrayfields['t.amount']['checked'])) $totalarray['pos'][$totalarray['nbfield']] = ''; + } // Buttons print ''; diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 90839fe6e95..910ea92d5d1 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -105,3 +105,36 @@ ALTER TABLE llx_propal ADD INDEX idx_propal_fk_warehouse(fk_warehouse); ALTER TABLE llx_product_customer_price ADD COLUMN ref_customer varchar(30); ALTER TABLE llx_product_customer_price_log ADD COLUMN ref_customer varchar(30); + +create table llx_paiementtva +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_tva integer, + datec datetime, -- date de creation + tms timestamp, + datep datetime, -- payment date + amount double(24,8) DEFAULT 0, + fk_typepaiement integer NOT NULL, + num_paiement varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, -- creation user + fk_user_modif integer -- last modification user + +)ENGINE=innodb; + +ALTER TABLE llx_tva ADD paye smallint default 0 NOT NULL; +ALTER TABLE llx_tva ADD fk_account integer; + +INSERT INTO `llx_paiementtva` (fk_tva, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_bank, fk_user_creat, fk_user_modif) +SELECT rowid, NOW(), datep, amount, COALESCE(fk_typepayment, 0), num_payment, '', fk_bank, fk_user_creat, fk_user_modif FROM llx_tva; + +UPDATE llx_bank_url url INNER JOIN llx_tva tva ON tva.rowid = url.url_id SET type = 'vat', url.label = CONCAT('(', tva.label, ')') WHERE type = 'payment_vat'; + +INSERT INTO `llx_bank_url` (fk_bank, url_id, url, label, type) +SELECT b.fk_bank, ptva.rowid, REPLACE(b.url, 'tva/card.php', 'payment_vat/card.php'), '(paiement)', 'payment_vat' +FROM llx_bank_url b INNER JOIN llx_tva tva ON (tva.fk_bank = b.fk_bank) INNER JOIN llx_paiementtva ptva on (ptva.fk_bank = b.fk_bank) +WHERE type = "vat"; + +ALTER TABLE llx_tva DROP COLUMN fk_bank; +UPDATE llx_tva SET paye = 1;