add the clone action for a social contribution

- With option to clone it to the next month by default
This commit is contained in:
Alexis Algoud 2014-09-23 16:52:15 +02:00
parent aba4c90d2b
commit 691658cde3
3 changed files with 105 additions and 7 deletions

View File

@ -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);
}
}
/*
@ -239,7 +301,18 @@ if ($id > 0)
$head=tax_prepare_head($object);
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
if ($action == 'paid')
{
@ -419,6 +492,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>";
}
// 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
if ($user->rights->tax->charges->supprimer)

View File

@ -106,7 +106,24 @@ class ChargeSociales extends CommonObject
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
@ -121,12 +138,11 @@ class ChargeSociales extends CommonObject
// Nettoyage parametres
$newamount=price2num($this->amount,'MT');
// Validation parametres
if (! $newamount > 0 || empty($this->date_ech) || empty($this->periode))
{
$this->error="ErrorBadParameter";
return -2;
}
if(!$this->check()) {
$this->error="ErrorBadParameter";
return -2;
}
$this->db->begin();

View File

@ -204,3 +204,6 @@ ACCOUNTING_VAT_ACCOUNT=Default accountancy code for collecting VAT
ACCOUNTING_VAT_BUY_ACCOUNT=Default accountancy code for paying VAT
ACCOUNTING_ACCOUNT_CUSTOMER=Accountancy code by default for customer 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