Skip to content
Snippets Groups Projects
Commit d6385fe1 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #1917 from atm-alexis/feature_add_clone_to_social_contribution

add the clone action for a social contribution
parents 40c1b02a 691658cd
No related branches found
No related tags found
No related merge requests found
...@@ -149,6 +149,68 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr ...@@ -149,6 +149,68 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr
} }
} }
// Action clone object
if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; }
if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer))
{
$db->begin();
$originalId = $id;
$object = new ChargeSociales($db);
$object->fetch($id);
if ($object->id > 0)
{
$object->paye = 0;
$object->id = $object->ref = null;
if(GETPOST('clone_for_next_month') != '') {
$object->date_ech = strtotime('+1month', $object->date_ech);
$object->periode = strtotime('+1month', $object->periode);
}
if ($object->check())
{
$id = $object->create($user);
if ($id > 0)
{
$db->commit();
$db->close();
header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
}
else
{
$id=$originalId;
$db->rollback();
if (count($object->errors))
{
setEventMessage($object->errors, 'errors');
dol_print_error($db,$object->errors);
}
else
{
setEventMessage($langs->trans($object->error), 'errors');
dol_print_error($db,$object->error);
}
}
}
}
else
{
$db->rollback();
dol_print_error($db,$object->error);
}
}
/* /*
...@@ -240,6 +302,17 @@ if ($id > 0) ...@@ -240,6 +302,17 @@ if ($id > 0)
dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill'); dol_fiche_head($head, 'card', $langs->trans("SocialContribution"),0,'bill');
// Clone confirmation
if ($action === 'clone')
{
$formclone=array(
array('type' => 'checkbox', 'name' => 'clone_for_next_month','label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1),
);
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneTax'),$langs->trans('ConfirmCloneTax',$object->ref),'confirm_clone',$formclone,'yes');
}
// Confirmation de la suppression de la charge // Confirmation de la suppression de la charge
if ($action == 'paid') if ($action == 'paid')
{ {
...@@ -420,6 +493,12 @@ if ($id > 0) ...@@ -420,6 +493,12 @@ if ($id > 0)
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&amp;action=paid\">".$langs->trans("ClassifyPaid")."</a>"; print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/sociales/charges.php?id=$object->id&amp;action=paid\">".$langs->trans("ClassifyPaid")."</a>";
} }
// Clone
if ($user->rights->tax->charges->creer)
{
print "<a class=\"butAction\" href=\"".dol_buildpath("/compta/sociales/charges.php",1). "?id=$object->id&amp;action=clone\">".$langs->trans("ToClone")."</a>";
}
// Delete // Delete
if ($user->rights->tax->charges->supprimer) if ($user->rights->tax->charges->supprimer)
{ {
......
...@@ -106,7 +106,24 @@ class ChargeSociales extends CommonObject ...@@ -106,7 +106,24 @@ class ChargeSociales extends CommonObject
return -1; return -1;
} }
} }
/*
* Check if a social contribution can be created into database
*
*/
function check() {
$newamount=price2num($this->amount,'MT');
// Validation parametres
if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
{
return false;
}
return true;
}
/** /**
* Create a social contribution into database * Create a social contribution into database
...@@ -121,13 +138,12 @@ class ChargeSociales extends CommonObject ...@@ -121,13 +138,12 @@ class ChargeSociales extends CommonObject
// Nettoyage parametres // Nettoyage parametres
$newamount=price2num($this->amount,'MT'); $newamount=price2num($this->amount,'MT');
// Validation parametres if(!$this->check()) {
if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
{
$this->error="ErrorBadParameter"; $this->error="ErrorBadParameter";
return -2; return -2;
} }
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)";
......
...@@ -204,3 +204,6 @@ ACCOUNTING_VAT_ACCOUNT=Default accountancy code for collecting VAT ...@@ -204,3 +204,6 @@ ACCOUNTING_VAT_ACCOUNT=Default accountancy code for collecting VAT
ACCOUNTING_VAT_BUY_ACCOUNT=Default accountancy code for paying VAT ACCOUNTING_VAT_BUY_ACCOUNT=Default accountancy code for paying VAT
ACCOUNTING_ACCOUNT_CUSTOMER=Accountancy code by default for customer thirdparties ACCOUNTING_ACCOUNT_CUSTOMER=Accountancy code by default for customer thirdparties
ACCOUNTING_ACCOUNT_SUPPLIER=Accountancy code by default for supplier thirdparties ACCOUNTING_ACCOUNT_SUPPLIER=Accountancy code by default for supplier thirdparties
CloneTax=Clone a social contribution
ConfirmCloneTax=Confirm the clone of a social contribution
CloneTaxForNextMonth=Clone it for next month
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment