Skip to content

Commit

Permalink
Merge branch '5.0' of git@github.com:Dolibarr/dolibarr.git into 6.0
Browse files Browse the repository at this point in the history
Conflicts:
	htdocs/accountancy/journal/bankjournal.php
	htdocs/compta/bank/bankentries.php
	htdocs/install/mysql/migration/4.0.0-5.0.0.sql
  • Loading branch information
eldy committed Jul 15, 2017
2 parents cb87b31 + 4055ac8 commit ab6646d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 36 deletions.
24 changes: 22 additions & 2 deletions htdocs/accountancy/journal/bankjournal.php
Expand Up @@ -680,8 +680,28 @@
$reflabel = $langs->trans('Employee');
}

$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
if (! empty($tabcompany[$key]['id']))
{
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
}
else
{
$companystatic->id = 0;
$companystatic->name = '';
}
if (! empty($tabuser[$key]['id']))
{
$userstatic->id = $tabuser[$key]['id'];
$userstatic->lastname = $tabuser[$key]['lastname'];
$userstatic->firstname = $tabuser[$key]['firstname'];
}
else
{
$userstatic->id = 0;
$userstatic->lastname = '';
$userstatic->firstname = '';
}

// Bank
foreach ( $tabbq[$key] as $k => $mt ) {
Expand Down
16 changes: 7 additions & 9 deletions htdocs/compta/localtax/quadri_detail.php
Expand Up @@ -54,8 +54,9 @@
$year_current = $year;
$year_start = $year;
}
$date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]);
$date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]);

$date_start = dol_mktime( 0, 0, 0, GETPOST( "date_startmonth" ), GETPOST( "date_startday" ), GETPOST( "date_startyear" ) );
$date_end = dol_mktime( 23, 59, 59, GETPOST( "date_endmonth" ), GETPOST( "date_endday" ), GETPOST( "date_endyear" ) );
// Quarter
if (empty($date_start) || empty($date_end)) // We define date_start and date_end
{
Expand Down Expand Up @@ -92,12 +93,9 @@
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');



/*
/**
* View
*/

$morequerystring='';
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
foreach($listofparams as $param)
Expand All @@ -118,6 +116,7 @@

$fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
$fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
$fsearch.=' <input type="hidden" name="localTaxType" value="'.$local.'">';

$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;

Expand Down Expand Up @@ -196,9 +195,8 @@
$i=0;

// Load arrays of datas
$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');

$x_coll = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');

echo '<table class="noborder" width="100%">';

Expand Down
53 changes: 40 additions & 13 deletions htdocs/core/lib/tax.lib.php
Expand Up @@ -181,11 +181,12 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
}

/**
* Gets VAT to collect for the given year (and given quarter or month)
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines.
* Gets Tax to collect for the given year (and given quarter or month)
* The function gets the Tax in split results, as the Tax declaration asks
* to report the amounts for different Tax rates as different lines.
* This function also accounts recurrent invoices.
*
* @param string $type Tax type, either 'vat', 'localtax1' or 'localtax2'
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Quarter
Expand All @@ -196,7 +197,7 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
* @param int $m Month
* @return array List of quarters with vat
*/
function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
{
global $conf;

Expand All @@ -210,8 +211,6 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$fk_facture2='fk_facture';
$fk_payment='fk_paiement';
$total_tva='total_tva';
$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';
$paymenttable='paiement';
$paymentfacturetable='paiement_facture';
$invoicefieldref='facnumber';
Expand All @@ -224,21 +223,28 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$fk_facture2='fk_facturefourn';
$fk_payment='fk_paiementfourn';
$total_tva='tva';
$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';
$paymenttable='paiementfourn';
$paymentfacturetable='paiementfourn_facturefourn';
$invoicefieldref='ref';
}

if ( strpos( $type, 'localtax' ) === 0 ) {
$f_rate = $type . '_tx';
} else {
$f_rate = 'tva_tx';
}

$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';

// CAS DES BIENS

// Define sql request
$sql='';
if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services
{
// 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.tva_tx 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.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, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -273,7 +279,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
else // Option vat on delivery for goods (payments) and payments for services
{
// 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.tva_tx 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.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 as date_f, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -378,7 +384,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
if ($modetax == 1) // Option vat on delivery for goods (payment) and debit invoice for services
{
// Count on invoice date
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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.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, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -413,7 +419,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
else // Option vat on delivery for goods (payments) and payments for services
{
// Count on payments date
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_tx 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.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, s.nom as company_name, s.rowid as company_id,";
Expand Down Expand Up @@ -522,7 +528,7 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
$sql='';

// Count on payments date
$sql = "SELECT e.rowid, d.product_type as dtype, e.rowid as facid, d.tva_tx 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 e.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 .=" 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,";
$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, s.nom as company_name, s.rowid as company_id, d.fk_c_type_fees as type,";
Expand Down Expand Up @@ -622,3 +628,24 @@ function vat_by_date($db, $y, $q, $date_start, $date_end, $modetax, $direction,
return $list;
}

/**
* Gets VAT to collect for the given year (and given quarter or month)
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines.
* This function also accounts recurrent invoices.
*
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Quarter
* @param string $date_start Start date
* @param string $date_end End date
* @param int $modetax 0 or 1 (option vat on debit)
* @param int $direction 'sell' (customer invoice) or 'buy' (supplier invoices)
* @param int $m Month
* @return array List of quarters with vat
*/
function vat_by_date ($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
{
return tax_by_date('vat', $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m);
}

22 changes: 10 additions & 12 deletions htdocs/install/mysql/migration/4.0.0-5.0.0.sql
Expand Up @@ -135,7 +135,7 @@ CREATE TABLE llx_product_lot_extrafields

ALTER TABLE llx_product_lot_extrafields ADD INDEX idx_product_lot_extrafields (fk_object);

ALTER TABLE llx_website_page MODIFY content MEDIUMTEXT;
ALTER TABLE llx_website_page MODIFY COLUMN content MEDIUMTEXT;

CREATE TABLE llx_product_warehouse_properties
(
Expand All @@ -161,7 +161,7 @@ ALTER TABLE llx_accounting_account ADD UNIQUE INDEX uk_accounting_account (accou

ALTER TABLE llx_expensereport_det ADD COLUMN fk_code_ventilation integer DEFAULT 0;

ALTER TABLE llx_c_payment_term change fdm type_cdr tinyint;
ALTER TABLE llx_c_payment_term CHANGE COLUMN fdm type_cdr tinyint;


ALTER TABLE llx_facturedet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx;
Expand All @@ -174,11 +174,10 @@ ALTER TABLE llx_supplier_proposaldet ADD COLUMN vat_src_code varchar(10) DEFAULT
ALTER TABLE llx_supplier_proposaldet ADD COLUMN fk_unit integer DEFAULT NULL;
ALTER TABLE llx_contratdet ADD COLUMN vat_src_code varchar(10) DEFAULT '' AFTER tva_tx;

ALTER TABLE llx_c_payment_term change fdm type_cdr tinyint;
ALTER TABLE llx_c_payment_term CHANGE COLUMN fdm type_cdr TINYINT;

ALTER TABLE llx_entrepot ADD COLUMN fk_parent integer DEFAULT 0;


create table llx_resource_extrafields
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
Expand Down Expand Up @@ -207,6 +206,8 @@ ALTER TABLE llx_overwrite_trans ADD COLUMN entity integer DEFAULT 1 NOT NULL AFT
ALTER TABLE llx_mailing_cibles ADD COLUMN error_text varchar(255);

ALTER TABLE llx_c_actioncomm MODIFY COLUMN type varchar(50) DEFAULT 'system' NOT NULL;
-- VPGSQL8.2 ALTER TABLE llx_c_actioncomm ALTER COLUMN type SET DEFAULT 'system';
-- VPGSQL8.2 ALTER TABLE llx_c_actioncomm ALTER COLUMN type SET NOT NULL;

create table llx_user_employment
(
Expand Down Expand Up @@ -241,12 +242,12 @@ ALTER TABLE llx_expensereport ADD INDEX idx_expensereport_fk_refuse (fk_user_app
DELETE FROM llx_actioncomm_resources WHERE fk_actioncomm not in (select id from llx_actioncomm);

-- Sequence to removed duplicated values of llx_links. Use serveral times if you still have duplicate.
drop table tmp_links_double;
DROP TABLE tmp_links_double;
--select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2;
create table tmp_links_double as (select objectid, label, max(rowid) as max_rowid, count(rowid) as count_rowid from llx_links where label is not null group by objectid, label having count(rowid) >= 2);
CREATE TABLE tmp_links_double AS (SELECT objectid, label, MAX(rowid) AS max_rowid, COUNT(rowid) AS count_rowid FROM llx_links WHERE label IS NOT NULL GROUP BY objectid, label HAVING COUNT(rowid) >= 2);
--select * from tmp_links_double;
delete from llx_links where (rowid, label) in (select max_rowid, label from tmp_links_double); --update to avoid duplicate, delete to delete
drop table tmp_links_double;
DELETE FROM llx_links WHERE (rowid, label) IN (SELECT max_rowid, label FROM tmp_links_double); --update to avoid duplicate, delete to delete
DROP TABLE tmp_links_double;

ALTER TABLE llx_links ADD UNIQUE INDEX uk_links (objectid,label);

Expand All @@ -257,8 +258,7 @@ ALTER TABLE llx_projet_task ADD UNIQUE INDEX uk_projet_task_ref (ref, entity);

ALTER TABLE llx_contrat ADD COLUMN fk_user_modif integer;


UPDATE llx_accounting_account set account_parent = 0 where account_parent = '';
UPDATE llx_accounting_account SET account_parent = 0 WHERE account_parent = '';

-- VMYSQL4.3 ALTER TABLE llx_product_price MODIFY COLUMN date_price DATETIME NULL;
-- VPGSQL8.2 ALTER TABLE llx_product_price ALTER COLUMN date_price DROP NOT NULL;
Expand All @@ -269,10 +269,8 @@ ALTER TABLE llx_product_customer_price ADD COLUMN default_vat_code varchar(10) a
ALTER TABLE llx_product_customer_price_log ADD COLUMN default_vat_code varchar(10) after tva_tx;
ALTER TABLE llx_product_fournisseur_price ADD COLUMN default_vat_code varchar(10) after tva_tx;


ALTER TABLE llx_events MODIFY COLUMN ip varchar(250);


UPDATE llx_bank SET label= '(SupplierInvoicePayment)' WHERE label= 'Règlement fournisseur';
UPDATE llx_bank SET label= '(CustomerInvoicePayment)' WHERE label= 'Règlement client';

0 comments on commit ab6646d

Please sign in to comment.