Skip to content
Snippets Groups Projects
Commit c6c07bf9 authored by Alexandre SPANGARO's avatar Alexandre SPANGARO
Browse files

New : Add project to social contributions

parent 7103d792
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
/* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
*
* 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
......@@ -28,6 +28,11 @@ require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
if (! empty($conf->projet->enabled))
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
}
$langs->load("compta");
$langs->load("bills");
......@@ -35,6 +40,7 @@ $langs->load("bills");
$id=GETPOST('id','int');
$action=GETPOST("action");
$confirm=GETPOST('confirm');
$projectid = (GETPOST('projectid') ? GETPOST('projectid', 'int') : 0);
// Security check
$socid = GETPOST('socid','int');
......@@ -43,8 +49,6 @@ $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
$object = new ChargeSociales($db);
/* *************************************************************************** */
/* */
/* Actions */
......@@ -122,6 +126,7 @@ if ($action == 'add' && $user->rights->tax->charges->creer)
$dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear'));
$amount=price2num(GETPOST('amount'));
$actioncode=GETPOST('actioncode');
if (! $dateech)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors');
......@@ -149,13 +154,14 @@ if ($action == 'add' && $user->rights->tax->charges->creer)
}
else
{
$object->type=$actioncode;
$object->lib=GETPOST('label');
$object->date_ech=$dateech;
$object->periode=$dateperiod;
$object->amount=$amount;
$object->mode_reglement_id = GETPOST('mode_reglement_id');
$object->fk_account = GETPOST('fk_account', 'int');
$object->type = $actioncode;
$object->lib = GETPOST('label');
$object->date_ech = $dateech;
$object->periode = $dateperiod;
$object->amount = $amount;
$object->mode_reglement_id = GETPOST('mode_reglement_id');
$object->fk_account = GETPOST('fk_account', 'int');
$object->fk_project = GETPOST('fk_project');
$id=$object->create($user);
if ($id <= 0)
......@@ -172,6 +178,7 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr
$dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear'));
$dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear'));
$amount=price2num(GETPOST('amount'));
if (! $dateech)
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("DateDue")), null, 'errors');
......@@ -196,10 +203,11 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr
{
$result=$object->fetch($id);
$object->lib=GETPOST('label');
$object->date_ech=$dateech;
$object->periode=$dateperiod;
$object->amount=price2num($amount);
$object->lib = GETPOST('label');
$object->date_ech = $dateech;
$object->periode = $dateperiod;
$object->amount = price2num($amount);
$object->fk_project = GETPOST("fk_project");
$result=$object->update($user);
if ($result <= 0)
......@@ -325,6 +333,21 @@ if ($action == 'create')
print '<td><input type="text" size="6" name="amount" class="flat" value="'.GETPOST('amount').'"></td>';
print '</tr>';
// Project
if (! empty($conf->projet->enabled))
{
$formproject=new FormProjets($db);
// Associated project
$langs->load("projects");
print '<tr><td>'.$langs->trans("Project").'</td><td>';
$numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1);
print '</td></tr>';
}
// Payment Mode
print '<tr><td>' . $langs->trans('PaymentMode') . '</td><td colspan="2">';
$form->select_types_paiements($mode_reglement_id, 'mode_reglement_id');
......@@ -485,6 +508,22 @@ if ($id > 0)
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
}
// Project
if (! empty($conf->projet->enabled)){
print '<tr><td class="nowrap">';
print $langs->trans("Project");
print '</td><td>';
if ($action == 'edit') {
$formproject=new FormProjets($db);
$numproject=$formproject->select_projects(-1,$object->fk_project,'fk_project',16,0,1,1);
} else {
$project=new Project($db);
$project->fetch($object->fk_project);
print $project->getNomUrl(1,'',1);;
}
print '</td></tr>';
}
// Mode of payment
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
......
......@@ -2,6 +2,7 @@
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2016 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
*
* 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
......@@ -52,6 +53,7 @@ class ChargeSociales extends CommonObject
var $date_modification;
var $date_validation;
var $fk_account;
var $fk_project;
/**
......@@ -75,7 +77,7 @@ class ChargeSociales extends CommonObject
function fetch($id, $ref='')
{
$sql = "SELECT cs.rowid, cs.date_ech";
$sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, cs.import_key";
$sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.fk_projet as fk_project, cs.paye, cs.periode, cs.import_key";
$sql.= ", cs.fk_account, cs.fk_mode_reglement";
$sql.= ", c.libelle";
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
......@@ -93,20 +95,21 @@ class ChargeSociales extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->date_ech = $this->db->jdate($obj->date_ech);
$this->lib = $obj->lib;
$this->type = $obj->fk_type;
$this->type_libelle = $obj->libelle;
$this->fk_account = $obj->fk_account;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement_libelle;
$this->amount = $obj->amount;
$this->paye = $obj->paye;
$this->periode = $this->db->jdate($obj->periode);
$this->import_key = $this->import_key;
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->date_ech = $this->db->jdate($obj->date_ech);
$this->lib = $obj->lib;
$this->type = $obj->fk_type;
$this->type_libelle = $obj->libelle;
$this->fk_account = $obj->fk_account;
$this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement_libelle;
$this->amount = $obj->amount;
$this->fk_project = $obj->fk_project;
$this->paye = $obj->paye;
$this->periode = $this->db->jdate($obj->periode);
$this->import_key = $this->import_key;
$this->db->free($resql);
......@@ -166,13 +169,15 @@ class ChargeSociales extends CommonObject
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, entity, fk_user_author, date_creation)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, fk_projet, entity, fk_user_author, date_creation)";
$sql.= " VALUES (".$this->type;
$sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL');
$sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"NULL");
$sql.= ", '".$this->db->escape($this->lib)."'";
$sql.= ", '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."'";
$sql.= ", '".$this->db->idate($this->date_ech)."'";
$sql.= ", '".$this->db->idate($this->periode)."'";
$sql.= ", '".price2num($newamount)."'";
$sql.= ", ".($this->fk_project>0?$this->fk_project:'NULL');
$sql.= ", ".$conf->entity;
$sql.= ", ".$user->id;
$sql.= ", '".$this->db->idate($now)."'";
......@@ -283,6 +288,7 @@ class ChargeSociales extends CommonObject
$sql.= ", date_ech='".$this->db->idate($this->date_ech)."'";
$sql.= ", periode='".$this->db->idate($this->periode)."'";
$sql.= ", amount='".price2num($this->amount,'MT')."'";
$sql.= ", fk_projet='".$this->db->escape($this->fk_project)."'";
$sql.= ", fk_user_modif=".$user->id;
$sql.= " WHERE rowid=".$this->id;
......@@ -302,7 +308,7 @@ class ChargeSociales extends CommonObject
}
/**
* Enter description here ...
* Calculate amount remaining to pay by year
*
* @param int $year Year
* @return number
......
......@@ -464,7 +464,7 @@ class FormProjets
if ($table_element == 'projet_task') return ''; // Special cas of element we never link to a project (already always done)
$linkedtothirdparty=false;
if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement'))) $linkedtothirdparty=true;
if (! in_array($table_element, array('don','expensereport_det','expensereport','loan','stock_mouvement','chargesociales'))) $linkedtothirdparty=true;
$sqlfilter='';
$projectkey="fk_projet";
......@@ -507,6 +507,7 @@ class FormProjets
$sql = 'SELECT t.rowid, t.label as ref';
$projectkey='fk_origin';
break;
case "chargesociales":
default:
$sql = "SELECT t.rowid, t.ref";
break;
......
......@@ -114,3 +114,5 @@ UPDATE llx_const set value='moono-lisa' where value = 'moono' AND name = 'FCKEDI
ALTER TABLE llx_product_price 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_chargesociales ADD COLUMN fk_projet integer DEFAULT NULL;
-- ========================================================================
-- Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
--
-- 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
......@@ -19,23 +20,24 @@
create table llx_chargesociales
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
date_ech datetime NOT NULL, -- date echeance
libelle varchar(80) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp,
date_creation datetime, -- date de creation
date_valid datetime, -- date de validation
fk_user_author integer, -- user making creation
fk_user_modif integer, -- user making last change
fk_user_valid integer, -- user validating
fk_type integer NOT NULL,
fk_account integer, -- bank account
fk_mode_reglement integer, -- mode de reglement
amount real default 0 NOT NULL,
paye smallint default 0 NOT NULL,
periode date,
import_key varchar(14)
rowid integer AUTO_INCREMENT PRIMARY KEY,
date_ech datetime NOT NULL, -- date echeance
libelle varchar(80) NOT NULL,
entity integer DEFAULT 1 NOT NULL, -- multi company id
tms timestamp,
date_creation datetime, -- date de creation
date_valid datetime, -- date de validation
fk_user_author integer, -- user making creation
fk_user_modif integer, -- user making last change
fk_user_valid integer, -- user validating
fk_type integer NOT NULL,
fk_account integer, -- bank account
fk_mode_reglement integer, -- mode de reglement
amount real default 0 NOT NULL,
paye smallint default 0 NOT NULL,
periode date,
fk_projet integer DEFAULT NULL,
import_key varchar(14)
)ENGINE=innodb;
--
......
......@@ -56,6 +56,7 @@ MenuTaxAndDividends=Taxes and dividends
MenuSocialContributions=Social/fiscal taxes
MenuNewSocialContribution=New social/fiscal tax
NewSocialContribution=New social/fiscal tax
AddSocialContribution=Add social/fiscal tax
ContributionsToPay=Social/fiscal taxes to pay
AccountancyTreasuryArea=Accountancy/Treasury area
NewPayment=New payment
......@@ -205,3 +206,4 @@ ImportDataset_tax_contrib=Social/fiscal taxes
ImportDataset_tax_vat=Vat payments
ErrorBankAccountNotFound=Error: Bank account not found
FiscalPeriod=Accounting period
ListSocialContributionAssociatedProject=List of social contributions associated with the project
......@@ -3,7 +3,7 @@
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Josep Lluís Amador <joseplluis@lliuretic.cat>
*
......@@ -34,25 +34,27 @@ 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->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
if (! empty($conf->supplier_proposal->enabled)) require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
if (! empty($conf->tax->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
$langs->load("projects");
$langs->load("companies");
$langs->load("suppliers");
$langs->load("compta");
if (! empty($conf->facture->enabled)) $langs->load("bills");
if (! empty($conf->commande->enabled)) $langs->load("orders");
if (! empty($conf->propal->enabled)) $langs->load("propal");
......@@ -406,7 +408,20 @@ $listofreferent=array(
'table'=>'stock_mouvement',
'datefieldname'=>'datem',
'disableamount'=>0,
'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && ! empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW)))
'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && ! empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))),
'chargesociales'=>array(
'name'=>"SocialContribution",
'title'=>"ListSocialContributionAssociatedProject",
'class'=>'ChargeSociales',
'margin'=>'add',
'table'=>'chargesociales',
'datefieldname'=>'date_ech',
'disableamount'=>0,
'urlnew'=>DOL_URL_ROOT.'/compta/sociales/card.php?action=create&projectid='.$id,
'lang'=>'compta',
'buttonnew'=>'AddSocialContribution',
'testnew'=>$user->rights->tax->charges->lire,
'test'=>$conf->tax->enabled && $user->rights->tax->charges->lire)
/* No need for this, available on dedicated tab "Agenda/Events"
'agenda'=>array(
'name'=>"Agenda",
......@@ -539,7 +554,7 @@ foreach ($listofreferent as $key => $value)
// Special cases
if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
if ($tablename == 'don') $total_ht_by_line=$element->amount;
if ($tablename == 'don' || $tablename == 'chargesociales') $total_ht_by_line=$element->amount;
elseif ($tablename == 'stock_mouvement') $total_ht_by_line=$element->price*abs($element->qty);
elseif ($tablename == 'projet_task')
{
......@@ -564,7 +579,7 @@ foreach ($listofreferent as $key => $value)
if ($qualifiedfortotal) $total_ht = $total_ht + $total_ht_by_line;
if ($tablename == 'don') $total_ttc_by_line=$element->amount;
if ($tablename == 'don' || $tablename == 'chargesociales') $total_ttc_by_line=$element->amount;
elseif ($tablename == 'stock_mouvement') $total_ttc_by_line=$element->price*abs($element->qty);
elseif ($tablename == 'projet_task')
{
......@@ -865,9 +880,10 @@ foreach ($listofreferent as $key => $value)
$date=''; $total_time_by_line = null;
if ($tablename == 'expensereport_det') $date = $element->date; // No draft status on lines
elseif ($tablename == 'stock_mouvement') $date = $element->datem;
if ($tablename == 'chargesociales') $date = $element->date_ech;
elseif (! empty($element->status) || ! empty($element->statut) || ! empty($element->fk_status))
{
if ($tablename=='don') $date = $element->datedon;
if ($tablename == 'don') $date = $element->datedon;
if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order')
{
$date=($element->date_commande?$element->date_commande:$element->date_valid);
......@@ -927,7 +943,7 @@ foreach ($listofreferent as $key => $value)
{
$total_ht_by_line=null;
$othermessage='';
if ($tablename == 'don') $total_ht_by_line=$element->amount;
if ($tablename == 'don' || $tablename == 'chargesociales') $total_ht_by_line=$element->amount;
elseif ($tablename == 'stock_mouvement') $total_ht_by_line=$element->price*abs($element->qty);
elseif (in_array($tablename, array('projet_task')))
{
......@@ -967,7 +983,7 @@ foreach ($listofreferent as $key => $value)
if (empty($value['disableamount']))
{
$total_ttc_by_line=null;
if ($tablename == 'don') $total_ttc_by_line=$element->amount;
if ($tablename == 'don' || $tablename == 'chargesociales') $total_ttc_by_line=$element->amount;
elseif ($tablename == 'stock_mouvement') $total_ttc_by_line=$element->price*abs($element->qty);
elseif ($tablename == 'projet_task')
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment