diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php
index 059a3ccf544..0ccd450e0cb 100644
--- a/htdocs/compta/sociales/charges.php
+++ b/htdocs/compta/sociales/charges.php
@@ -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 "id&action=paid\">".$langs->trans("ClassifyPaid")."";
}
+
+ // Clone
+ if ($user->rights->tax->charges->creer)
+ {
+ print "id&action=clone\">".$langs->trans("ToClone")."";
+ }
// Delete
if ($user->rights->tax->charges->supprimer)
diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php
index 09e4ebaef0c..807466ef95f 100644
--- a/htdocs/compta/sociales/class/chargesociales.class.php
+++ b/htdocs/compta/sociales/class/chargesociales.class.php
@@ -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();
diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang
index 5ec9bd62a54..47e19c78d21 100644
--- a/htdocs/langs/en_US/compta.lang
+++ b/htdocs/langs/en_US/compta.lang
@@ -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
\ No newline at end of file