Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP NEW Add clone functionality on miscellaneous payment #14941

Merged
merged 3 commits into from Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions htdocs/compta/bank/class/paymentvarious.class.php
Expand Up @@ -338,6 +338,24 @@ public function initAsSpecimen()
$this->fk_user_modif = '';
}

/**
* Check if a miscellaneous payment can be created into database
*
* @return boolean True or false
*/
public function check()
{
$newamount = price2num($this->amount, 'MT');

// Validation of parameters
if (!($newamount) > 0 || empty($this->datep))
{
return false;
}

return true;
}

/**
* Create in database
*
Expand Down
82 changes: 80 additions & 2 deletions htdocs/compta/bank/various_payment/card.php
Expand Up @@ -41,8 +41,9 @@

// Get parameters
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm');
$cancel = GETPOST('cancel', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');

$accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0;
Expand Down Expand Up @@ -225,6 +226,64 @@
}
}

// Action clone object
if ($action == 'confirm_clone' && $confirm != 'yes') { $action = ''; }

if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier))
{
$db->begin();

$originalId = $id;

$object->fetch($id);

if ($object->id > 0)
{
$object->id = $object->ref = null;

if (GETPOST('clone_label', 'alphanohtml')) {
$object->label = GETPOST('clone_label', 'alphanohtml');
} else {
$object->label = $langs->trans("CopyOf").' '.$object->label;
}

$newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int'));
$newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int'));
if ($newdatepayment) $object->datep = $newdatepayment;
if (!empty($newdatevalue)) {
$object->datev = $newdatevalue;
} else {
$object->datev = $newdatepayment;
}

if ($object->check())
aspangaro marked this conversation as resolved.
Show resolved Hide resolved
{
$id = $object->create($user);
if ($id > 0)
{
$db->commit();
$db->close();

header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
exit;
} else {
$id = $originalId;
$db->rollback();

setEventMessages($object->error, $object->errors, 'errors');
}
} else {
$id = $originalId;
$db->rollback();

setEventMessages($object->error, $object->errors, 'errors');
}
} else {
$db->rollback();
dol_print_error($db, $object->error);
}
}


/*
* View
Expand Down Expand Up @@ -419,6 +478,19 @@

$head = various_payment_prepare_head($object);

// Clone confirmation
if ($action === 'clone')
{
$formquestion = array(
array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
);
$formquestion[] = array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1);
$formquestion[] = array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1);
$formquestion[] = array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($accountid, "accountid", 0, '', 1));

print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 300);
}

dol_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);

$morehtmlref = '<div class="refidno">';
Expand Down Expand Up @@ -542,6 +614,12 @@
// TODO
// Add button modify

// Clone
if ($user->rights->banque->modifier)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/bank/various_payment/card.php", 1).'?id='.$object->id.'&amp;action=clone">'.$langs->trans("ToClone")."</a></div>";
}

// Delete
if (empty($object->rappro))
{
Expand Down
4 changes: 2 additions & 2 deletions htdocs/compta/bank/various_payment/list.php
Expand Up @@ -490,9 +490,9 @@
print $accountstatic->getNomUrl(1);
} else {
print '&nbsp;';
print '</td>';
if (!$i) $totalarray['nbfield']++;
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
}

// Bank entry
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/banks.lang
Expand Up @@ -168,6 +168,7 @@ ShowVariousPayment=Show miscellaneous payment
AddVariousPayment=Add miscellaneous payment
VariousPaymentId=Miscellaneous payment ID
VariousPaymentLabel=Miscellaneous payment label
ConfirmCloneVariousPayment=Confirm the clone of a miscellaneous payment
SEPAMandate=SEPA mandate
YourSEPAMandate=Your SEPA mandate
FindYourSEPAMandate=This is your SEPA mandate to authorize our company to make direct debit order to your bank. Return it signed (scan of the signed document) or send it by mail to
Expand Down